Why do I receive an error when using "xlswrite" to write a cell array into a spreadsheet on MacOS?

I am using the function "xlswrite" to write a cell array containing numeric and text data to a file. However, I am receiving an error:
Error using dlmwrite The input cell array cannot be converted to a matrix.
 Why do I receive this error and how can I fix it?

 Accepted Answer

In order to use "xlswrite" on MacOS (or any system on which Excel is not available), the input must be a numeric matrix. This is a limitation of "xlswrite" .The following documentation page for "xlswrite" discusses this limitation. Please run the below command in the command window of installed MATLAB R2019a version to get release specific documentation for "xlswrite" function:
>> web(fullfile(docroot, 'matlab/ref/xlswrite.html'))
Additionally, as of MATLAB R2019a, we no longer recommend using "xlswrite" for cross-platform and performance reasons.
Instead, in MATLAB R2019a and later, use "writecell" to write the cell array to a CSV. Please run the below command in the command window of installed MATLAB R2019a version to get release specific documentation to read more information on "writecell" function:
>> web(fullfile(docroot, 'matlab/ref/writecell.html'))
In earlier releases, you can convert the cell array to a table using "cell2table" and then use "writetable" to write it to a CSV:
>> T = cell2table(myCellArray);
>> writetable(T, 'myCSVFile.csv');
 
Please follow the below link to search for the required information regarding the current release:

More Answers (0)

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!