matrix store issue for loop iteration
Afficher commentaires plus anciens
for i=1:3
------------
r=[s m]
The S and M matrix are 1 by 3 matrix. The result "r" matrix is 3 by 2.
The code above is generates combines 2 matrices that is S and M matrix. It generate r matrix output at i=1 upto i =3, but the only last value outputs are stored in "r" matrix that is for i=3.
Réponses (1)
KSSV
le 9 Oct 2020
r = cell(1,3) ;
for i = 1:3
r{i} = [s m]
end
If You feel r will have same size m*p in every iteration, you can initilaize this as a 3D matrix.
r = zeros(m,p,3) ;
for i = 1:3
r(:,:,i) = [s m] ;
end
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!