Index exceeds matrix dimensions error
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
I'm trying to plot the following, and I keep getting "Index exceeds matrix dimensions." I have six files that start with "timeds*.mat" and I can't see where I'm going wrong. Any help would be appreciated!
files=dir('timeds*.mat');
mycolours=jet(6);
figure(1);clf
for i=1:length(files)
load (files(i).name)
plot(data.serial,data.sdespike,'color',mycolours(i,:))
hold on
ylabel('Salinity [psu]')
%ylim([30 35])
datetick('x','mmm-yy')
end
legend('AS04','BNDYP','JF2C09','JF2C','JFCN09','JFCN')
1 件のコメント
Walter Roberson
2013 年 11 月 22 日
Which line is the error occurring on? Is it the plot() line? If so then you would have a problem if more than 6 files turned out to be present. What does length(files) show after you dir() ?
回答 (1 件)
Roger Stafford
2013 年 11 月 22 日
0 投票
Judging by the line "mycolours=jet(6)", 'mycolours' would be a scalar variable, and yet you attempt to index it with "mycolours(i,:)" where i would become greater than 1 if length(files) is greater than 1. This would account for the error message you are quoting.
1 件のコメント
Walter Roberson
2013 年 11 月 22 日
jet() is the name of a function. Like all of the colormap generating functions it takes a parameter which is the number of entries to use.
The colormaps are all defined as functions. pink, copper, flag, jet, hot -- all of them are functions. jet(6) would return a 6 x 3 matrix.
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!