Change colours of different lines in for loop plot
1 回表示 (過去 30 日間)
古いコメントを表示
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
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 Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!