Why am I unable to set the 'Color' property for multiple line plots in MATLAB using a single call to the PLOT function?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 6 Mai 2011
Commenté : Rub Ron
le 23 Juil 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.
Réponse acceptée
MathWorks Support Team
le 6 Mai 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 commentaire
Rub Ron
le 23 Juil 2020
what is "h" has large number of elements, how to assign them all at once? something like this:
set(h(:), 'color', matrixOfColors)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!