Use the same color multiple times in a plotting loop

조회 수: 38 (최근 30일)
Ralf Niemann
Ralf Niemann 2013년 7월 23일
Hello everyone,
I have a problem with a plotting loop, where I am plotting the spectral data and following the fit. For the reason of clarity I want to have them both in the same color, however matlab switches to the next color in order. Can anyone give me hint how to avoid this?
Ralf
  댓글 수: 3
Ralf Niemann
Ralf Niemann 2013년 7월 24일
exactly that. I hope this makes my problem more clear:
folder=dir('*.csv');
for i=1:length(folder)
file=folder(i,1).name;
A=csvread(file);
plot(A(:,1),A(:,2));
hold all
f(:,1)=A(:,1);
f(:,2)=smooth(A(:,2),0.01,'lowess');
plot(f(:,1),f(:,2),'--');
end
Ralf Niemann
Ralf Niemann 2013년 7월 24일
problem solved:
folder=dir('*.csv');
cc=lines(length(folder));
for i=1:length(folder)
file=folder(i,1).name;
A=csvread(file);
plot(A(:,1),A(:,2),'Color',cc(i,:));
hold all
f(:,1)=A(:,1);
f(:,2)=smooth(A(:,2),0.01,'lowess');
plot(f(:,1),f(:,2),'Color',cc(i,:),'--');
end

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

채택된 답변

Narges M
Narges M 2013년 7월 24일
편집: Narges M 2013년 7월 24일
You could use a colormap such as HSV to generate a set of colors. For example:
folder=dir('*.csv');
N = length(folder);
col=hsv(N);
for i=1:N
file=folder(i,1).name;
A=csvread(file);
plot(A(:,1),A(:,2),'color',col(i,:));
hold all
f(:,1)=A(:,1);
f(:,2)=smooth(A(:,2),0.01,'lowess');
plot(f(:,1),f(:,2),'--','color',col(i,:));
end

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by