Info
This question is closed. Reopen it to edit or answer.
Index exceeds matrix dimensions error
3 views (last 30 days)
Show older comments
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 Comment
Walter Roberson
on 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() ?
Answers (1)
Roger Stafford
on 22 Nov 2013
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 Comment
Walter Roberson
on 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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!