Store results of for loop in matrix

2 vues (au cours des 30 derniers jours)
Tchilabalo
Tchilabalo le 20 Août 2019
Commenté : Tchilabalo le 20 Août 2019
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.

Réponse acceptée

Stephen23
Stephen23 le 20 Août 2019
Modifié(e) : Stephen23 le 20 Août 2019
  1 commentaire
Tchilabalo
Tchilabalo le 20 Août 2019
It works. Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by