how to write for loop with two variables

Hello, I'm having problem with this it of code:
for j = 1:3
for m = 3:-1:1
imagesc(images{m}, 'XData', [fid1(j,1) (size(Image1,2) + fid1(j,1))], 'YData',[fid2(j,1) (size(Image1, 1) + fid2(j,1))]), axis equal, axis xy
alpha(0.7)
hold on
end
end
As you can see, I want the images{m} to start from 3 and end at 1, while the fid1(j,1) commands to go in the opposite direction. Any ideas how to solve this? One idea I had was to flip my images{m} array but I'm not sure how to do this
Thanks

 採用された回答

Image Analyst
Image Analyst 2014 年 7 月 22 日

0 投票

Try
images = fliplr(images); % or flipud() - what ever works.
Or
images = images(end:-1:1);

3 件のコメント

mika maka
mika maka 2014 年 7 月 22 日
thanks that works, but what about the for loop, is it not possible for it have two variables? I don't quite understand why this does not work.
Joseph Cheng
Joseph Cheng 2014 年 7 月 22 日
編集済み: Joseph Cheng 2014 年 7 月 22 日
*cough* well if you take a look at the answer below. you can see how to get 2 variables to work. why your nested (is that the right term?) for loop doesn't really do what you want is because it'll do all combination of m for each j. so for j=1 you'll run through it for m=3,2,1 and then for j=2 you'll run through it again for m=3,2,1 and so on.
Joseph Cheng
Joseph Cheng 2014 年 7 月 22 日
編集済み: Joseph Cheng 2014 年 7 月 22 日
Oh and additionally thinking about it more you could have had
m=length(images);
for j = 1:3
imagesc(images{m+1-j}, 'XData', [fid1(j,1) (size(Image1,2) + fid1(j,1))], 'YData',[fid2(j,1) (size(Image1, 1) + fid2(j,1))])
axis equal
axis xy
alpha(0.7)
hold on
end

サインインしてコメントする。

その他の回答 (1 件)

Joseph Cheng
Joseph Cheng 2014 年 7 月 22 日
編集済み: Joseph Cheng 2014 年 7 月 22 日

1 投票

make an array called index = 3:-1:1;
for j = 1:3
m=index(j);
imagesc(images{m}, 'XData', [fid1(j,1) (size(Image1,2) + fid1(j,1))], 'YData',[fid2(j,1) (size(Image1, 1) + fid2(j,1))])
axis equal
axis xy
alpha(0.7)
hold on
end

カテゴリ

ヘルプ センター および File ExchangeDeep Learning Toolbox についてさらに検索

質問済み:

2014 年 7 月 22 日

編集済み:

2014 年 7 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by