matrix store issue for loop iteration
显示 更早的评论
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.
回答(1 个)
KSSV
2020-10-9
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
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!