Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Sample code in xlsread fails

Asked by farhan on 17 Nov 2012

I am learning about xls file handling and tried some sample code from the Matlab doc file:

xlsread>Read Data from First Worksheet Into Numeric Array

http://www.mathworks.com/help/matlab/ref/xlsread.html

The code is

values = {1, 2, 3 ; 4, 5, 'x' ; 7, 8, 9};
headers = {'First', 'Second', 'Third'};
xlswrite('myExample.xlsx', [headers; values]);

and the output I get is

Warning: Could not start Excel server for export.
XLSWRITE will attempt to write file in CSV format. 
> In xlswrite at 175
  In plot_from_XL at 14 
Error using xlswrite (line 188)
An error occurred on data export in CSV format.
Error in plot_from_XL (line 14)
xlswrite('myExample.xlsx', [headers; values]);
Caused by:
    Error using dlmwrite (line 118)
    The input cell array cannot be converted to a matrix.

The relevant issue is not the Excel server (whatever that is), but with dlmwrite, because if I try a .csv version:

values = {1, 2, 3 ; 4, 5, 'x' ; 7, 8, 9};
headers = {'First', 'Second', 'Third'};
csvwrite('myExample.csv', [headers; values]);

I get a similar error:

Error using dlmwrite (line 118)
The input cell array cannot be converted to a matrix.
Error in csvwrite (line 43)
dlmwrite(filename, m, ',', r, c);
Error in plot_from_XL (line 10)
csvwrite('myExample.csv', [headers; values]);

I have to think this is some kind of bug in the dlmwrite function.

Any suggestions?

0 Comments

farhan

Products

1 Answer

Answer by Image Analyst on 17 Nov 2012

It works fine for me. I'd say you either don't have Excel installed at all, or you have the Excel "starter edition" that comes free with many computers (like my home computer) and that version is not allowed to do ActiveX operations like xlswrite() does. csvwrite() probably just uses fprintf() to create a text file and does not use Excel as a server.

2 Comments

farhan on 19 Nov 2012

Thanks for the suggestion, and for trying the code! I am on a Mac and have Excel 2011 installed. Also, the csvwrite code doesn't elicit the Excel error.

Image Analyst on 19 Nov 2012

Sorry, I can't help you with that operating system.

Image Analyst

Contact us