Cannot import excel xls files

1 回表示 (過去 30 日間)
Chelsea Dong
Chelsea Dong 2016 年 9 月 15 日
コメント済み: Image Analyst 2016 年 9 月 16 日
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!

回答 (2 件)

Image Analyst
Image Analyst 2016 年 9 月 15 日
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 件のコメント
Chelsea Dong
Chelsea Dong 2016 年 9 月 16 日
編集済み: Chelsea Dong 2016 年 9 月 16 日
Thank you for the advice! I tried other ways (including xlsread) but still could not do the work.
Image Analyst
Image Analyst 2016 年 9 月 16 日
Attach the file so someone else can try it.

サインインしてコメントする。


Star Strider
Star Strider 2016 年 9 月 16 日
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.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by