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

What is your code?
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.

댓글을 달려면 로그인하십시오.

 채택된 답변

dpb
dpb 2018년 1월 9일
편집: dpb 2018년 1월 9일
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개)

카테고리

질문:

2018년 1월 9일

댓글:

dpb
2018년 1월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by