custom colors in plot (without loop)

조회 수: 11 (최근 30일)
Rainer
Rainer 2015년 8월 31일
댓글: Rainer 2015년 8월 31일
Hi, suppose I have a custom color array:
c=[1 0 0
0 1 0
0 0 1]
Is there a way use the color array in a plot without looping? The following doesn't work:
plot(rand(100,3),'color',c)

채택된 답변

Kelly Kearney
Kelly Kearney 2015년 8월 31일
편집: Kelly Kearney 2015년 8월 31일
Another option is to set the color after plotting via the cell array set syntax:
c = [...
1 0 0
0 1 0
0 0 1];
h = plot(rand(100,3));
set(h, {'color'}, num2cell(c,2));
It requires an extra line of code, but I've always found this much easier than messing with default color order, hold settings, etc.
  댓글 수: 1
Rainer
Rainer 2015년 8월 31일
Thanks, this is a great solution.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by