How can I write a cell array containing strings to excel?

Hi, I have a cell array containing character arrays, numeric data and strings. The character arrays and numeric data are correctly written to excel, but the strings have disappeared.

3 个评论

I have a table, called analysisTable, of which the field catNo contains strings. If I write it to an excel file like this
analysisTable=table2cell(analysisTable);
xlswrite(filename,analysisTable(:,1:end-4),'Analysis','A11');
the catNo field is gone. For now, I added this code before the table2cell command:
analysisTable.catNo=cellfun(@char,analysisTable.catNo,'UniformOutput',0)
This seems to solve my problem - although I still think it is weird that I cannot directly write strings to excel.
...I still think it is weird that I cannot directly write strings to excel.
See Answer; documented behavior.

请先登录,再进行评论。

 采纳的回答

From the documentation,
...
A — Input matrix
matrix
Input matrix, specified as a two-dimensional numeric or character array, or, if each cell
contains a single element, a cell array.
If A is a cell array containing something other than a scalar numeric or text, then xlswrite
silently leaves the corresponding cell in the spreadsheet empty.
...
Just confirmed with R2016b that XLSWRITE has not been upgraded to handle the native string type; you'll have to cast each cell containing a string to character string to use it.
I'd presume it would be on the "to do" list, but submitting an enhancement request might bring it to the top of the pile sooner...
PS. TMW: The most frustrating part of this is the "silent" part; at least a warning would be helpful...

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by