Error reading excel sheet: index out of bounds.

9 views (last 30 days)
Hi all,
Sorry to bother. I'm stuck on a bit of code. It worked initially with one column of data, but when I tried to use a different column, I got this error message:
Attempted to access yearsh(30133); index out of bounds because numel(yearsh)=30132.
Error in SeasonalCorrection (line 16) year = yearsh(i); %Names variables for each iteration
Problematic part of the code:
%Opens the file you listed and takes the four columns individually
yearsh = xlsread(filename,sheetnumber,yearcol);
monthsh = xlsread(filename,sheetnumber,monthcol);
daysh = xlsread(filename,sheetnumber,daycol);
icesh = xlsread(filename,sheetnumber,icecol);
%Creates a cell array with enough openings for each data point
edited = cell(range,5);
%Takes each data point individually
for i = 1:range; year = yearsh(i); %Names variables for each iteration month = monthsh(i); day = daysh(i); ice = icesh(i);
The excel sheet it's referencing has holes in the data, but this didn't cause any issue with the first column I tried, though it also had its fair share of holes in it. The holes are just blanks, not zeros. Later they're taken out of the sheet, and that didn't cause any issues with the first column I tried.
Any idea what's going on? I'd like for it to be generic enough that it can take in any excel sheet and any columns and run the operations, but it seems to want to stay put on the first column...
Thanks!

Accepted Answer

Sean de Wolski
Sean de Wolski on 2 Jul 2014
What is range? Apparently it's bigger than 30132, the size of yearsh.
  4 Comments
Kate
Kate on 2 Jul 2014
I think I understand. So I ran it a few other times, and the yearsh never seemed to be a problem again, now it's just icesh. Which kind of makes sense, as it has blanks in the beginning in the excel sheet, and it skips over those when moving into matlab. I just need to find a way to hold their places and just leave it blank when it gets read over, preferably putting them in as NaN... Thank you so much! I've never used dpstop before.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!