필터 지우기
필터 지우기

plotting an array in different colors

조회 수: 44 (최근 30일)
Aditya
Aditya 2014년 3월 24일
댓글: Aditya 2014년 3월 26일
I have a 2D array y(m,p) where p can range from 1 to 100. I want to plot y(m,1) to y(m,n) in differrnt colors.Each color should be different without any repetition and with an appropriate legend.Is there a way to do this.Thanks in advance.

채택된 답변

Mischa Kim
Mischa Kim 2014년 3월 24일
편집: Mischa Kim 2014년 3월 24일
Aditya, check out the sample code below:
my_col = jet(20);
t = 0:0.1:pi;
a = 1:length(my_col(:,1));
y = a'*sin(t);
hold all
for ii = 1:numel(a)
plot(y(ii,:),'color',my_col(ii,:))
leg{ii} = strcat('data',num2str(ii));
end
legend(leg)
  댓글 수: 1
Aditya
Aditya 2014년 3월 26일
Thanks a lot.This is the perfect example. Just wanted to know why the colors of the legend get repeated for values greater than 8. I want different colors for different integer values.
Here's my code:
my_col = jet(20);
hold(handles.axes6);
plot(handles.axes6,y,'Linewidth',1.5);
legend(uni); % uni contains a set of strings
hold(handles.axes6);
Thanks in advance.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by