Cannot read .xslx file
이전 댓글 표시
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?
답변 (1개)
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
Nicholas Howe
2024년 4월 3일
Nicholas Howe
2024년 4월 3일
Star Strider
2024년 4월 4일
My only suggestion is to re-start MATLAB, and be certain you have all the available updates installed. Check that by clicking on the top toolbar ‘Resources’ tab —> ‘Help’ —> ‘Check for Updates’. (I have never seen the problem you are having before.)
Nicholas Howe
2024년 4월 17일
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.)
.
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!