Error reading excel sheet: index out of bounds.
9 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Sean de Wolski
on 2 Jul 2014
What is range? Apparently it's bigger than 30132, the size of yearsh.
4 Comments
Sean de Wolski
on 3 Jul 2014
If you use the import tool to import the data, you can change how it handles unimportable cells.
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!