MATLAB 2019b readtable opts.DataRange import bug
5 次查看(过去 30 天)
显示 更早的评论
I am working with externally created Output.xlsx file importing it for the following processing. The code I am using:
fileToRead = 'OutputFile.xlsx'; %Enter name of file
mainSheet = 2; %Enter main sheet
%---------------------Parameters-for-Data-Reading--------------------------
opts = detectImportOptions(fileToRead, 'sheet', mainSheet, 'ReadVariableNames', false);
if (~isequal(opts.DataRange,'A19'))
opts.DataRange = 'A19';
end
%----------------------------Opening-of-xlsx-------------------------------
CostsFile = readtable('EnvironmentalCost.xlsx', 'ReadVariableNames', 1, 'ReadRowNames', 1);
Input1 = readtable(fileToRead, opts);
i=[1,14,27,40,53,66,79,92];
ValueMatrix = table2array(Input1(1:end,23:end));
if (~isequal(class(ValueMatrix),'double'))
ValueMatrix = str2double(ValueMatrix);
end
This code throws an error:![Annotation 2019-10-15 154233.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/242779/Annotation%202019-10-15%20154233.png)
![Annotation 2019-10-15 154233.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/242779/Annotation%202019-10-15%20154233.png)
But, when I change the code in following way, without using opts. and directly opening the sheet it works.
%----------------------------Opening-of-xlsx-------------------------------
CostsFile = readtable('EnvironmentalCost.xlsx', 'ReadVariableNames', 1, 'ReadRowNames', 1);
Input1 = readtable('OutputFile.xlsx', 'sheet', 2);% - working for output file
i=[1,14,27,40,53,66,79,92];
ValueMatrix = table2array(Input1(18:end,23:end));
if (~isequal(class(ValueMatrix),'double'))
ValueMatrix = str2double(ValueMatrix);
end
This proves that there should be no errors within the table and there are no variables that are double and cell, but for some reason the error is thrown.
Another point is if I use another file generated by the same software and that has the same structure and as well data starts from A19, then everything works perfectly
fileToRead = 'Projekt A Analyse LCA.xlsx';
mainSheet = 1; %Enter main sheet
%---------------------Parameters-for-Data-Reading--------------------------
opts = detectImportOptions(fileToRead, 'sheet', mainSheet, 'ReadVariableNames', false);
if (~isequal(opts.DataRange,'A19'))
opts.DataRange = 'A19';
end
%----------------------------Opening-of-xlsx-------------------------------
CostsFile = readtable('EnvironmentalCost.xlsx', 'ReadVariableNames', 1, 'ReadRowNames', 1);
Input1 = readtable(fileToRead, opts);
i=[1,14,27,40,53,66,79,92];
ValueMatrix = table2array(Input1(1:end,23:end));
if (~isequal(class(ValueMatrix),'double'))
ValueMatrix = str2double(ValueMatrix);
end
ValueMatrix(isnan(ValueMatrix))=0;
So far I could not figure where is the problem and now considering submitting a bug report.
Is there any ideas how to fix this problem?
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Install Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!