matlab - Build Diagonal in for loop -


trying append matrix in for loop diagonally:

for ii=1:10      r1 = [1,2;3,4]; matrix 2x2 different values each iteration       cov = blkdiag(r1); end 

obviously won't work since rewriting on value. want build matrix consists of r1 values such this

[ r1,0,0,0...,    0,r1,0,0...] 

i can accomplish end goal employing other techniques curious if can done in for loop

r1 = [1,2;3,4];                              %// initial r1 matrix currentout = r1;                             %// initialise output ii = 1:10     r1 = [1,2;3,4];                          %// placeholder function generates r1     [a,b] = size(currentout);                %// current size     tmpout(a+2,b+2)=0;                       %// extend current size     tmpout(1:a,1:b) = currentout;            %// copy current matrix     tmpout(a+1:end,b+1:end) = r1;            %// add additional element     currentout=tmpout;                       %// update original end 

as said, for loop not best way of doing this, can indeed done.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -