2
votes

I have two computers with the same MATLAB code and same Excel file (.csv format). The code only works on the machine that has Excel. I can't think of any other differences.

Does a computer need Excel for xlsread to work? The error I'm getting is an unrecognized format.

If this is the case, are there any easy workarounds without getting Excel?

EDIT: It appears that Excel is not needed. Maybe the issue is that the file is a .csv? It is a format error after all. I just can't imagine why a file of the same format worked on my other computer.

SOLVED: The .csv file was the problem. For reading .csv files, the importdata() function of matlab proved to be really versatile.

3
A csv file is not, repeat NOT an Excel file. It is an ascii text file which happens to use a comma as a delimiter. Why are you using an Excel-reading function rather than any of the builtin text-file tools? - Carl Witthoft
PLease read the posting guidelines and supply your actual code that is failing to read the file and a small, reproducible sample text file. - Carl Witthoft

3 Answers

6
votes

According to this page

If your system has Excel® for Windows® installed, including the COM server (part of the typical installation of Excel):

All MATLAB® import options support XLS, XLSX, XLSB, XLSM, XLTM, and XLTX formats.

...

If your system does not have Excel for Windows installed, or the COM server is not available:

All MATLAB import options read XLS, XLSX, XLSM, XLTM, and XLTX files.

However, if you are just trying to import a comma delimited ASCII file, then xlsread is way overkill and super slow. If your data is purely numeric, use csvread or dlmread. If your data is mixed, then use textscan instead.

3
votes

xlsread(filename,sheet,xlRange,'basic') will work without Excel installed on your machine.

Other additional arguments will require Excel to be installed.

Matlab can import character separated files natively though.

2
votes

I have never used xlsread on a computer without Excel, so I can't be sure. But according to the documentation Excel is not necessary; you only lose some functionality:

num = xlsread(filename,sheet,xlRange,'basic') reads data from the spreadsheet in basic import mode. If your computer does not have Excel for Windows®, xlsread automatically operates in basic import mode, which supports XLS, XLSX, XLSM, XLTX, and XLTM files.

basic mode is the default for computers without Excel for Windows. In basic mode, xlsread:

  • Reads XLS, XLSX, XLSM, XLTX, and XLTM files only.

  • Does not support an xlRange input when reading XLS files. In this case, use '' in place of xlRange.

  • Does not support function handle inputs.

  • Imports all dates as Excel serial date numbers. Excel serial date numbers use a different reference date than MATLAB® date numbers.

So, perhaps the problem is that you are calling xlsread with some options that are not supported in basic mode.