Error reading excel sheet: index out of bounds.
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Sean de Wolski
2014-7-2
What is range? Apparently it's bigger than 30132, the size of yearsh.
4 个评论
Sean de Wolski
2014-7-3
If you use the import tool to import the data, you can change how it handles unimportable cells.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!