How can I use a matrix to be a loop variable
4 次查看(过去 30 天)
显示 更早的评论
For example, in usual for loop, it looks like that
for i=1:1:10
disp(i)
end
if I want the variable to be a matrix,like:
for mat = set of matrices
imshow(mat);
end
the set of matrices is composed of {mat1,mat2,mat3,mat4}
1 个评论
Bob Thompson
2019-3-1
I don't believe it's possible for a for loop index to be larger than a 1x1 size. That doesn't mean though that it's not possible to use the matrices within your loop. How are your matrices related? What type of organization do you have for them?
采纳的回答
Honglei Chen
2019-3-1
If you have somethign like
mat = {mat1,mat2,mat3,mat4}
You can do
for m = 1:numel(mat)
imshow(mat{m})
end
HTH
3 个评论
Walter Roberson
2019-3-2
You can also do
for m = {mat1, mat2, mat3, mat4}
figure()
imshow(m{1})
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!