how to change color for a 2D plot

Dear all,
I have a 2D plot, in which consist of 5 line to make a "closed cell", I wish to color the line with different color. so I try it as below
x = [0.168149323 0.547990492 0.580721962 0.502272216 0.321295719 0.168149323];
y = [0.565541486 0.530969047 0.570321397 0.878624621 1.069086578 0.565541486];
z = [0 0 0 0 0 0];
%rgb is colormap value for different line
rgb= [0.5020 0 0
0.5000 0 0
0.5000 0 0
0 0 0.5156
0 0 0.5156]
for k = 1 : length(rgb);
hold on
% Get new values.
plot(x, y,'-', 'Color', rgb(k,:) ,'LineWidth',2)
end
but all the line I get has same color instead of different color, may I know how can I make them different color based on my colormap matrix?
Thank you in advance.

 採用された回答

KSSV
KSSV 2021 年 12 月 20 日

2 投票

x = [0.168149323 0.547990492 0.580721962 0.502272216 0.321295719 0.168149323];
y = [0.565541486 0.530969047 0.570321397 0.878624621 1.069086578 0.565541486];
figure
hold on
for i = 2:length(x)
plot(x((i-1):i),y((i-1):i),'-')
end

1 件のコメント

wei ong
wei ong 2021 年 12 月 20 日
Thank you very much @KSSV, I got it!

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

その他の回答 (0 件)

カテゴリ

質問済み:

2021 年 12 月 20 日

コメント済み:

2021 年 12 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by