Index exceeds matrix dimensions error
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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 Kommentar
Walter Roberson
am 22 Nov. 2013
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() ?
Antworten (1)
Roger Stafford
am 22 Nov. 2013
0 Stimmen
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 Kommentar
Walter Roberson
am 22 Nov. 2013
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.
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!