Simultanious for loop (two variables)

1 view (last 30 days)
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

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 15 Aug 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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!