Why am I unable to set the 'Color' property for multiple line plots in MATLAB using a single call to the PLOT function?

28 views (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 6 May 2011
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]);

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!