matlab - Why doesn't `spdiags` put a vector in the correct place? -


i have vector has 1's in places, , want create diagonal using vector. vector called one_vec_two:

n = 4;  one_vec_two = zeros(n*n, 1); one_vec_two(1,1) = 1; k=0:(n-1)     one_vec_two(k*n+1, 1) = 1; end  non_zero_vecs = [one_vec_two]; placement = [n-1];  = spdiags(non_zero_vecs, placement, n*n, n*n); fulla = full(a); disp(a) 

the first element of vector one_vec_two 1:

>> one_vec_two(1)  ans =       1 

and, placed vector starting @ diagonal n-1, 3. but, when go column 4, don't see it:

>> fulla(1,4)  ans =       0 

why isn't matlab putting vector in correct spot?

as per doc spdiag,

note in syntax, if column of b longer diagonal replacing, , m >= n, spdiags takes elements of super-diagonals lower part of column of b, , elements of sub-diagonals upper part of column of b.

it placing lower part of vector location specified. hence result expected.

it looks want like

a = spdiags(non_zero_vecs([end-placement+1:end 1:end-placement]), placement, n*n, n*n) 

or

a = spdiags(non_zero_vecs, -placement, n*n, n*n)' 

which both same thing, in different ways.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -