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

 Réponse acceptée

Image Analyst
Image Analyst le 22 Juil 2014
Try
images = fliplr(images); % or flipud() - what ever works.
Or
images = images(end:-1:1);

3 commentaires

mika maka
mika maka le 22 Juil 2014
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 le 22 Juil 2014
Modifié(e) : Joseph Cheng le 22 Juil 2014
*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 le 22 Juil 2014
Modifié(e) : Joseph Cheng le 22 Juil 2014
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

Connectez-vous pour commenter.

Plus de réponses (1)

Joseph Cheng
Joseph Cheng le 22 Juil 2014
Modifié(e) : Joseph Cheng le 22 Juil 2014
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

Catégories

En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by