Simultanious for loop (two variables)

1 visualizzazione (ultimi 30 giorni)
Karl
Karl il 15 Ago 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

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 15 Ago 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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by