"Index exceeds array bounds"
4 次查看(过去 30 天)
显示 更早的评论
I have quite a simple for loop that goes into an excel file and collects a range of cells in every sheet of the file. The folder has 12 excel files and every file has a data for each month in each sheets. Need help Please
folder='2018';
filetype='*.xlsx';
f=fullfile(folder,filetype);
d=dir(f);
for i=1:numel(d);
filename=fullfile(folder,d(i).name);
[status,sheets] = xlsfinfo(filename);
for s=1:24 %numel(sheets);
output_0cm{s}=xlsread(filename,sheets{s},'D42:D42');
output_15cm{s}=xlsread(filename,sheets{s},'F42:F42');
output_22_8cm{s}=xlsread(filename,sheets{s},'H42:H42');
end
end
Mean_0cm=output_0cm{3:length(output_0cm)}
3 个评论
madhan ravi
2018-12-26
Thank you for the good insight. The folder 2018 has 12 files in it representing each month of the year hence (for i=1:numel(d); will return 1-12.Each month has 1-24 sheets in it. My code goes into each sheet for each month and pulls out the required cells as shown. You are right though, the code will overide the returned data for the first 11 months and return just that for the last month on in the folder.
I don't quite understand how to fix this issue. I will like "output_0cm{s}" to have 12 rows, representing each month of the year. Right now im just getting 1 row and 24 coulumns for the month of December. Any suggestions?
dpb
2018-12-27
Well, then, there needs to be 12(mo) x 24(shts) x 3(vars) of storage available as data array or some other structure to hold that much data by indexing over the variables' ranges.
Just what would be most useful depends at least in part on what is the need...what is to be done with the 24 copies of what is, apparently, the same variable? Is that what is to be averaged?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!