Cannot read .xslx file
2 次查看(过去 30 天)
显示 更早的评论
I am trying to read in the attached .xslx file. It is a very simple file: thirteen rows, four columns, all string data. Neither readcell nor readtable works properly. With readcell I get only the first column of data. With readtable I get an error:
>> f = readtable('Agora_I_4985.xlsx')
Error using readtable
Index exceeds the number of array elements. Index must not exceed 1.
517 throw(ME)
K>>
Given the simplicity of the file, I am very surprised that this doesn't just work out of the box. What am I missing?
0 个评论
回答(1 个)
Star Strider
2024-4-3
The R2024a version of readtable has no problems with it. Does this seem to be correct?
T1 = readtable('Agora_I_4985.xlsx', 'VariableNamingRule','preserve')
It is possible that you have a variable named ‘readtable’. To check, run this from a script or your Command Window —
which readtable -all
The result should be exactly as it is here. If ther are other entries, that is likely the problem. The solution is to re-name the variable to something that does not overshadow any MATLAB function, and makes sense in the context of the code using it.
.
5 个评论
Star Strider
2024-4-17
Another option is to use MATLAB Online until you can get the problem with your home installation repaired. It has all the Toolboxes you have licensed, however only those. You can copy-paste the results if necessary, and copy-paste any code you write to your home installation.
To import the file to MATLAB Online, you can either use the ‘Import Data’ tab to import the file, or:
filename = websave('Agora_I_4985','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1659291/Agora_I_4985.xlsx')
T1 = readtable(filename, 'VariableNamingRule','preserve')
in your script to read it and work with it.
(I just now tested those commands in MATLAB Online to confirm that they work. They do, and the file imoprts correctly.)
.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!