Sample code in xlsread fails
1 view (last 30 days)
Show older comments
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
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
Answers (1)
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
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!