Cannot import excel xls files
3 views (last 30 days)
Show older comments
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!
0 Comments
Answers (2)
Image Analyst
on 15 Sep 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 Comments
Star Strider
on 16 Sep 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.
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!