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 comentarios

What is your code?
Vilvoorde Elabqc
Vilvoorde Elabqc el 9 de En. de 2018
Editada: dpb el 9 de En. de 2018
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.
dpb
dpb el 9 de En. de 2018
...I still think it is weird that I cannot directly write strings to excel.
See Answer; documented behavior.

Iniciar sesión para comentar.

 Respuesta aceptada

dpb
dpb el 9 de En. de 2018
Editada: dpb el 9 de En. de 2018
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...

Más respuestas (0)

Etiquetas

Preguntada:

el 9 de En. de 2018

Comentada:

dpb
el 9 de En. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by