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

1 回表示 (過去 30 日間)
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.

採用された回答

MathWorks Support Team
MathWorks Support Team 2011 年 5 月 6 日
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 件のコメント
Rub Ron
Rub Ron 2020 年 7 月 23 日
what is "h" has large number of elements, how to assign them all at once? something like this:
set(h(:), 'color', matrixOfColors)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by