Prev: Convert mat to txt
Next: no loops
From: roya olyazadeh on 17 May 2010 13:49 I have matrix like this : Q = 1 2 3 4 5 6 Now I want to add some zero cells to this matrix like this for i = 1 : length(stn) % number of station if fix1(i)==1 % If station is fixed ????? % Add row i and column i that all = 0 end end for example i=1 Q= 0 0 0 0 0 1 2 3 0 4 5 6
From: Nathan on 17 May 2010 13:57 On May 17, 10:49 am, "roya olyazadeh" <roya2...(a)gmail.com> wrote: > I have matrix like this : > > Q = > 1 2 3 > 4 5 6 > > Now I want to add some zero cells to this matrix like this > > for i = 1 : length(stn) % number of station > if fix1(i)==1 % If station is fixed > > ????? % Add row i and column i that all = 0 > > end > end > for example i=1 > Q= > 0 0 0 0 > 0 1 2 3 > 0 4 5 6 Better yet, we don't need a for loop: Q = [zeros(1,size(Q,2)+1);zeros(size(Q,1),1) Q] Works for any arbitrary matrix Q where you want to pad the top and the left with zeros. -Nathan
|
Pages: 1 Prev: Convert mat to txt Next: no loops |