matrix store issue for loop iteration
Mostrar comentarios más antiguos
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.
Respuestas (1)
KSSV
el 9 de Oct. de 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
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!