Why am I unable to set the 'Color' property for multiple line plots in MATLAB using a single call to the PLOT function?
1 view (last 30 days)
Show older comments
MathWorks Support Team
on 6 May 2011
Commented: Rub Ron
on 23 Jul 2020
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
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]);
1 Comment
Rub Ron
on 23 Jul 2020
what is "h" has large number of elements, how to assign them all at once? something like this:
set(h(:), 'color', matrixOfColors)
More Answers (0)
See Also
Categories
Find more on Annotations 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!