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

 采纳的回答

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

3 个评论

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.
*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.
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 个)

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 Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by