Cannot import excel xls files

3 visualizaciones (últimos 30 días)
Chelsea Dong
Chelsea Dong el 15 de Sept. de 2016
Comentada: Image Analyst el 16 de Sept. de 2016
Hi,
I am trying to import xls files to Matlab, but failed with both 'importdata' and 'xlsread', or even manually.
For example, I tried with the import data icon and the following window pops up:
However, if I save the xls file as xlsx, Matlab reads xlsx the file correctly. But there are lots of files and I cannot possibly re-save them all.
I am using OS X EI Capitan. Could this be the problem? I have tried Matlab2014a and 2016a, and the problem is always there.
Is there any way I can fix it? Thanks a lot!

Respuestas (2)

Image Analyst
Image Analyst el 15 de Sept. de 2016
Who cares how you read it in? If importdata() doesn't work, don't worry about it and move on to something that works. Just use whatever works. If xlsread() works, use that. If readtable() works, you can use that too.
  2 comentarios
Chelsea Dong
Chelsea Dong el 16 de Sept. de 2016
Editada: Chelsea Dong el 16 de Sept. de 2016
Thank you for the advice! I tried other ways (including xlsread) but still could not do the work.
Image Analyst
Image Analyst el 16 de Sept. de 2016
Attach the file so someone else can try it.

Iniciar sesión para comentar.


Star Strider
Star Strider el 16 de Sept. de 2016
If you need to rename your .xls files to .xlsx to use them, you can use the movefile function in a loop version of this example code snippet:
fido = fopen('test.xls','w'); % Create Empty Example File
fclose(fido); % Close
full_old_file_name = which('test.xls') % Find Example File
movefile('test.xls', 'test.xlsx'); % Rename Example File
full_new_file_name = which('test.xlsx') % Find Renamed Example File
full_old_file_name = which('test.xls') % Verify Old Example File No Longer Exists
delete(full_new_file_name) % Delete Example File
I didn’t try to open and read the file (there’s nothing in it and xlsread would not be amused and probably throw an error) but the renaming with movefile works (in R2016a on Windows 8.1).
First, experiment with my code on your system to be certain it works, before you do it with an actual data file. I leave the coding details to you. You will obviously need to use the dir function to get a full list of the .xls files you want to rename.

Community Treasure Hunt

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

Start Hunting!

Translated by