Export data using xlswrite. Data is in a cell array and numerical matrix.
2 views (last 30 days)
Show older comments
Hello,
I'm having trouble with the following code in the mac environment (which is probably half the problem). When I export the numerical array it nicely creates a CSV file for me. When I try to export the strings (cell array " B" ) in column B1, MATLAB gives me the following error message:
" Warning: Could not start Excel server for export. XLSWRITE will attempt to write file in CSV format. > In xlswrite at 175 In test_code at 38
Warning: Could not start Excel server for export. XLSWRITE will attempt to write file in CSV format. > In xlswrite at 175 In test_code at 39
Error using xlswrite (line 188) An error occurred on data export in CSV format. Error in test_code (line 39) xlswrite(filename,B,1,'B1') Caused by: Error using dlmwrite (line 113) The input cell array cannot be converted to a matrix. "
A=[ 0.1100, 0.1200, 0.1300, 0.1400, 0.1500, 0.1600, 0.1700, 0.1800, 0.1900, 0.2000, 0.2100, 0.2200, 0.2300, 0.2400, 0.2500, 0.2600, NaN, NaN]'
B={'a2','bf-4','csf3', 'd#$%', 'e45@', 'f-0-0-0', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',[], []}'
filename='results.csv';
xlswrite(filename,A,1,'A1')
xlswrite(filename,B,1,'B1')
1 Comment
Bill Rooker
on 29 Oct 2015
Hello everyone,
I am seeing the same issue with my code. It used to work. I am now using R2015b. Will it work on older versions? Thanks.
Regards,
Bill Rooker
Answers (1)
Kirby Fears
on 29 Oct 2015
Edited: Kirby Fears
on 29 Oct 2015
The warning and error messages you receive are indicating (1) an Excel COM server cannot be opened on your machine, (2) direct writing to .csv is attempted instead of opening Excel, and (3) dlmwrite is called via xlswrite, but fails to write because "input cell array cannot be converted to matrix".
Look at the dlmwrite documentation -- it states that non-numeric arrays are not valid inputs. It fails to write B because B is a non-numeric cell array. Therefore you cannot use xlswrite to make your desired output.
You should avoid using xlswrite as a Mac user because of these issues. You could call dlmwrite directly if you want to output numeric arrays instead of calling xlswrite and watching it struggle to write a csv file (csv is NOT an Excel-specific format, though Excel can read it). Even on Windows, there's no reason to use xlswrite to write a .csv file.
Here are two ways to export your non-numeric cell array to a .csv file.
0 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!