Clear Filters
Clear Filters

Cannot read .xslx file

32 views (last 30 days)
Nicholas Howe
Nicholas Howe on 3 Apr 2024 at 21:15
Commented: Star Strider on 17 Apr 2024 at 16: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?

Answers (1)

Star Strider
Star Strider on 3 Apr 2024 at 21:29
The R2024a version of readtable has no problems with it. Does this seem to be correct?
T1 = readtable('Agora_I_4985.xlsx', 'VariableNamingRule','preserve')
T1 = 12x4 table
Agora_I_4985_Rotation1_300dpi_line01.png Agora_I_4985_Rotation2_300dpi_line01.png STOKAI STOKAI_1 ____________________________________________ ____________________________________________ _____________ _____________ {'Agora_I_4985_Rotation1_300dpi_line02.png'} {'Agora_I_4985_Rotation2_300dpi_line02.png'} {'ODIKOSES' } {'*DIKOSE*' } {'Agora_I_4985_Rotation1_300dpi_line03.png'} {'Agora_I_4985_Rotation2_300dpi_line03.png'} {'IHIDIKHT' } {'IHIDIKHT' } {'Agora_I_4985_Rotation1_300dpi_line04.png'} {'Agora_I_4985_Rotation2_300dpi_line04.png'} {'OSENNEAR' } {'OSENNEA*' } {'Agora_I_4985_Rotation1_300dpi_line05.png'} {'Agora_I_4985_Rotation2_300dpi_line05.png'} {'AYTOIDI' } {'AYTOID*' } {'Agora_I_4985_Rotation1_300dpi_line06.png'} {'Agora_I_4985_Rotation2_300dpi_line06.png'} {'NEANTISA' } {'NEANTISA' } {'Agora_I_4985_Rotation1_300dpi_line07.png'} {'Agora_I_4985_Rotation2_300dpi_line07.png'} {'SIASEANTO'} {'SIASEANT*'} {'Agora_I_4985_Rotation1_300dpi_line08.png'} {'Agora_I_4985_Rotation2_300dpi_line08.png'} {'ODONAIEAN'} {'ODONAIEA*'} {'Agora_I_4985_Rotation1_300dpi_line09.png'} {'Agora_I_4985_Rotation2_300dpi_line09.png'} {'NPOLEWSAP'} {'NPOLEWSAP'} {'Agora_I_4985_Rotation1_300dpi_line10.png'} {'Agora_I_4985_Rotation2_300dpi_line10.png'} {'NIOSAQHN' } {'NIOSAQHN' } {'Agora_I_4985_Rotation1_300dpi_line11.png'} {'Agora_I_4985_Rotation2_300dpi_line11.png'} {'KAIPROSO' } {'*AIPROS*' } {'Agora_I_4985_Rotation1_300dpi_line12.png'} {'Agora_I_4985_Rotation2_300dpi_line12.png'} {'ILIONM' } {'ILIONM' } {'Agora_I_4985_Rotation1_300dpi_line13.png'} {'Agora_I_4985_Rotation2_300dpi_line13.png'} {'EAFE' } {'*AF*' }
It is possible that you have a variable named readtable’. To check, run this from a script or your Command Window —
which readtable -all
/MATLAB/toolbox/matlab/iofun/readtable.m /MATLAB/toolbox/shared/io/general/+matlab/+io/@ImportOptions/ImportOptions.m % matlab.io.text.DelimitedTextImportOptions method
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 Comments
Nicholas Howe
Nicholas Howe on 17 Apr 2024 at 13:51
I can confirm that this happens with my fresh install of R2024a. I will contact support as you suggest.
Star Strider
Star Strider on 17 Apr 2024 at 16:30
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.)
.

Sign in to comment.

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!