MATLAB Answers

0

Store results of for loop in matrix

Asked by Tchilabalo on 20 Aug 2019 at 16:28
Latest activity Commented on by Tchilabalo on 20 Aug 2019 at 17:19
ab=[X01(:) X02(:) a(:) m(:) b(:)];
Countcell=zeros(1, length(ab))
for i=1:length(ab)
X=[(ab(i,1)+(0:(ab(i,3)/dx):ab(i,3))*1),ab(i,2)]
Y=(ab(i,4).*X)+ab(i,5)
ncol=fix(X./CS)+1;
ncol=[ncol].';
nrow=fix(Y./CS)+1
nrow=[nrow].';
Ncell=[ncol, nrow]
Countcell=Ncell(i)
end
I am trying to store all the results of a for loop into one matrix. At each iteration, the result is an (n by 2) matrix. I cant use cell2mat because these matrices have different lengths. I have tried to pre-allocate, but without success.

  0 Comments

Sign in to comment.

1 Answer

Answer by Stephen Cobeldick on 20 Aug 2019 at 16:39
Edited by Stephen Cobeldick on 20 Aug 2019 at 16:43
 Accepted Answer

  1 Comment

Tchilabalo on 20 Aug 2019 at 17:19
It works. Thanks.

Sign in to comment.