Filter löschen
Filter löschen

How can I use a matrix to be a loop variable

4 Ansichten (letzte 30 Tage)
Ziyu Zhao
Ziyu Zhao am 1 Mär. 2019
Kommentiert: Ziyu Zhao am 2 Mär. 2019
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 Kommentar
Bob Thompson
Bob Thompson am 1 Mär. 2019
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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Honglei Chen
Honglei Chen am 1 Mär. 2019
If you have somethign like
mat = {mat1,mat2,mat3,mat4}
You can do
for m = 1:numel(mat)
imshow(mat{m})
end
HTH
  3 Kommentare
Walter Roberson
Walter Roberson am 2 Mär. 2019
You can also do
for m = {mat1, mat2, mat3, mat4}
figure()
imshow(m{1})
end
Ziyu Zhao
Ziyu Zhao am 2 Mär. 2019
yes, thanks a lot, this kind of structure is interesting, and very useful.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by