Matlab – How to specify color for mutliple lines in matlab plot

MATLABplot

I am using the following matlab plot to draw multiple points

plot(ydep, xvar, '.', 'Markersize', 3);

Here ydep and xvar are matrix of 1024×300, so there will be 300 dotted lines being plotted in random color. What my question is how to specify the color for each of 300 lines in the parameter? I try to use a loop to plot each 'line' but that's pretty slow

for n=1:300
  plot(ydep(:, n), xvar(:, n), '.', 'Markersize', 3, 'color', linecolors(n, :));
  hold on;
end

where linecolors defined the color for each of the line.

Best Answer

As mentioned in the comment, the solution is to set the ColorOrder. Then you can just plot it as a matrix with matlabs regular high performance.

Here is an example of how to set the ColorOrder

http://www.mathworks.com/matlabcentral/answers/19815-explicitly-specifying-line-colors-when-plotting-a-matrix

Related Topic