MATLAB: Am I unable to set the ‘Color’ property for multiple line plots in MATLAB using a single call to the PLOT function

colorMATLABmultipleplotsrgbvalues

I am trying to set the 'Color' property for multiple line plots in MATLAB using a single call to the PLOT function. However, when I try to do this using the following syntax, I get an error message.
plot(1:100,1:100,'color',[.5 .5 .5],1:100,1:100,'color',[.2 .2 .2])
??? Error using ==> plot
Vectors must be the same lengths.

Best Answer

The ability to set the 'Color' property for multiple line plots in MATLAB using a single call to the PLOT function is not available in MATLAB.
To work around this issue, generate the plots individually, specifying the desired 'Color' property value as shown below:
hold on
plot(1:100,1:100,'Color',[.5 .5 .5])
plot(100:-1:1,1:100,'Color',[.2 .2 .2])
Alternatively you can set the 'Color' property with the SET function as follows:
h = plot(1:100,1:100, 1:100, 1:100);
set(h(1), 'color', [.5 .5 .5]);
set(h(2), 'color', [.2 .2 .2]);