MATLAB: Do I receive an error when using “xlswrite” to write a cell array into a spreadsheet on MacOS

celldlmwritemacMATLABxlswrite

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?

Best 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 section of the documentation page for "xlswrite" discusses this limitation:
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. For more information, please refer to the following page:
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');