MATLAB: Each graph more than 100 with different colors from the beginning to the end in series

graph

How can I plot each graph that is more than 100 with different colors from the begining to the end in series? For example, there is 100 lines every 1 sec , I would like to change the color from 1sec to 100sec in series like rainbow color , gradually change from 1 sec to 100sec. we can set plot (x,y,'g')with few graphs , but I do not know how to set more than 100 lines in series easily. When I set plot(x,y) and there is more than 100 lines, it repeat same color at some interval since thre is not so much color selection, I would like to set more than 100 lines with different colors in series.

Best Answer

Try this:
x = linspace(0, 4*pi, 100);
numPlots = 100;
period = 55;
plotColors = hsv(numPlots);
for k = 1 : numPlots
y = sin(2*pi*x/period + k);
plot(x, y, 'Color', plotColors(k, :), 'LineWidth', 2);
hold on;
end
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
The call to hsv() will make 100 unique colors, which plot() then uses to plot that curve in that particular color.