MATLAB: How can i get same color graph in each iteration of for loop

graph with for loop

In my Matlab code, I am trying to merge two graphs in each iteration of for loop. I want the color of graph generated to be same for an iteration, but varying color with iteration

Best Answer

One approach, notice how I used color property of plot:
x=1:10;
y=2*x;
for i=1:numel(x)
a=rand(1,3);
plot(x(i),y(i),'Marker','o','color',a);hold on;plot(x(i)+1,y(i),'Marker','o','color',a);hold on;
end