Colour options in plotting graphs

1 view (last 30 days)
dandan din
dandan din on 3 Jul 2018
Answered: VBBV on 28 Jan 2022
I have two for-loops and i need to change the colour of the plot in every iteration of the outer for loop and the same colour for the inner for-loop. The code is as follows;
for t=0:0.01:1.5
f=@(time,y)[y(2);eqn];
for y20=0:0.1:1.5
hold on
[ts,ys] = ode45(f,[0,10],[y20;0]);
plot(ys(:,1),ys(:,2),'color',rand(1,3))
end
hold off
end

Answers (2)

KSSV
KSSV on 3 Jul 2018
figure
hold on
for i = 1:3
plot(rand(10,1),'r')
for j = 1:2
plot(rand(1,10),'color',rand(1,3))
end
end

VBBV
VBBV on 28 Jan 2022
figure
hold on
cc = 'rgbmyck'
cc = 'rgbmyck'
for i = 1:7
subplot(211)
plot(rand(10,1),'color',cc(i))
hold on
title('outer for loop')
for j = 1:2
subplot(212)
plot(rand(1,10),'color','r')
hold on
title('inner for loop')
end
end

Community Treasure Hunt

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

Start Hunting!