Simultanious for loop (two variables)

1 vue (au cours des 30 derniers jours)
Karl
Karl le 15 Août 2013
How do I make j = 1 when i = 2 and j = 2 when i = 3 in the loop below (that does not do this)?
a = rand(1,2);
b=rand(2,3);
myColorMap = lines(length(a));
for i = 2:3;
for j= 1:length(a);
hold on
plot(b(:,i), 'color', myColorMap((j), :));
end
end

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 15 Août 2013
a = rand(1,2);
b = rand(2,3);
myColorMap = lines(length(a));
s = size(b);
for jj = 1:length(a);
hold on
plot(b(:,s(jj)), 'color', myColorMap(jj, :));
end
  1 commentaire
Karl
Karl le 15 Août 2013
That worked. Thanks, Andrei!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by