It's readmatrix probably that's the problem as it is designed for matrix input and you have what looks like two (or several) matrices for the one column instead of just one. You can try subterfuge by specifying the range as the two columns something like:
range='C:D';
d=dir('2019_*.xlsx');
numFiles = length(d);
energy=zeros(numFiles,2);
for k = 1:numFiles
energy(k,:)=sum(readmatrix(d(k).name,'Range',range,'NumHeaderLines',1),'omitnan');
end
and I'm guessing it may work altho didn't try it.
If it still aborts on the missing data in column D, switch to readtable or use the detectImportOptions function first to build a SpreadsheetImportOptions object that can pass in which you can define how to treat missing data and the ranges that will override the internal logic that tries to impute what the data format of the input file is. But, I believe just using the two columns together where the one is complete will work (although it undoubtedly would break again if that column ever were to also have any missing value(s). The more robust coding solution would be to use the import options object.
NB: You don't need this redone every time, build one for the file structure and use it for each inside the loop.
0 Comments
Sign in to comment.