How to plot 2 different colour using RBG setting

plot(x,y,'color',[0,0.5,0], x,y2, 'color',[0.5,0,0])
It said
Error using plot
Vectors must be the same length.
If I am using:
plot(x,y,'color',[0,0.5,0]),
it works.

回答 (1 件)

Image Analyst
Image Analyst 2020 年 1 月 3 日

0 投票

Your y2 does not have the same number of elements as x. It has nothing to do with the colour.

3 件のコメント

Matlaber
Matlaber 2020 年 1 月 3 日
編集済み: Matlaber 2020 年 1 月 3 日
However, when I plot:
plot(x,y,'blue', x,y2,'red'),
it work.
Image Analyst
Image Analyst 2020 年 1 月 3 日
Yeah, weird - I don't know. However you can do it as two separate calls to plot with hold on in between:
x = 1 : 20;
y = rand(1, length(x));
y2 = rand(1, length(x));
plot(x,y, 'color', [0,0.5,0]);
hold on
plot(x,y2, 'color', [0.5,0,0])
Matlaber
Matlaber 2020 年 1 月 3 日
It works, in this case.
Thanks.
Not sure why join both plot together, it does not work.

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

カテゴリ

ヘルプ センター および File ExchangeColor and Styling についてさらに検索

質問済み:

2020 年 1 月 3 日

コメント済み:

2020 年 1 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by