Change colours of different lines in for loop plot

조회 수: 1 (최근 30일)
B C
B C 2013년 11월 20일
댓글: dpb 2013년 11월 20일
I ran the following a couple days ago and it produced a plot with different coloured lines for each station. I didn't change anything in the code below, but I did play around with the data .mat files a little to remove some spikes. I set bad data to NaN. This is the only thing I changed, and I don't understand why colours in a plot would change as a result. The only error I'm getting is "Index exceeds matrix dimensions. Thanks in advance for help!
files=dir('i*.mat');
mycolours=jet(5);
figure(1);clf
for i=1:length(files)
load (files(i).name)
plot(data.time,data.sdespike,'color',mycolours(i,:))
hold on
ylabel('Salinity [psu]')
%ylim([30 35])
%datetick('x','mmm-yy')
end
legend('AS04','BNDYP','JF2C','JFCN')
saveas(gcf,'mooringS', 'pdf')
figure(2)
for i=1:length(files)
load (files(i).name)
plot(data.time,data.tdespike,'color',mycolours(i,:))
hold on
ylabel('Temperature [^oC]')
%ylim([0 12])
%datetick('x','mmm-yy')
end
legend('AS04','BNDYP','JF2C','JFCN')
saveas(gcf,'mooringT', 'pdf')
figure(3)
for i=1:length(files)
load (files(i).name)
plot(data.time,data.pdespike,'color',mycolours(i,:))
hold on
ylabel('Pressure [dbar]')
%datetick('x','mmm-yy')
end
legend('AS04','BNDYP','JF2C','JFCN')
saveas(gcf,'mooringP', 'pdf')
figure(4)
for i=1:length(files)
load (files(i).name)
plot(data.time,data.odespike,'color',mycolours(i,:))
hold on
ylabel('Oxygen [ml/L]')
%datetick('x','mmm-yy')
end
legend('AS04','BNDYP','JF2C','JFCN')
saveas(gcf,'mooringO', 'pdf')
  댓글 수: 1
dpb
dpb 2013년 11월 20일
mycolours=jet(5);
for i=1:length(files)
load (files(i).name)
plot(data.time,data.sdespike,'color',mycolours(i,:))
There's no check that length(files)<=length(mycolours) so that could easily cause runover. Not sure but I'd expect that would disrupt the color map. Other than that don't see where the overrun might be but clearly first thing to do is to fix it...

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by