Concatenate cell array with double matrix

4 ビュー (過去 30 日間)
Mauro Baldi
Mauro Baldi 2015 年 6 月 1 日
コメント済み: Stephen23 2015 年 6 月 2 日
I need to create a (m + 1)*n cell matrix concatenating a cell array of strings named NomiDopo with a m*n matrix of double, DataSet. The final result must be a (m + 1)*n cell matrix of string, otherwise the xlswrite function does not write the correct values in the output spreadsheet. This means converting the original matrix of double DataSet into a matrix of string. I tried in many ways, also using the mat2cell function, but it didn't work. Can anybody help me, please? Thank you!
  1 件のコメント
Stephen23
Stephen23 2015 年 6 月 1 日
Are you using xlswrite? This function accepts mixed data in a cell array, have you tried using this? What happens that you do not expect? Are the values represented incorrectly?

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2015 年 6 月 1 日
編集済み: Stephen23 2015 年 6 月 1 日
You can use num2str inside arrayfun to convert numeric values to a cell-array of strings:
>> A = {'header_1','header_2'};
>> B = [0.1,2.3;4.5,6.7;8.9,NaN]
B =
0.1000 2.3000
4.5000 6.7000
8.9000 NaN
>> C = arrayfun(@num2str,B,'UniformOutput',false)
C =
'0.1' '2.3'
'4.5' '6.7'
'8.9' 'NaN'
>> [A;C]
ans =
'header_1' 'header_2'
'0.1' '2.3'
'4.5' '6.7'
'8.9' 'NaN
  2 件のコメント
Mauro Baldi
Mauro Baldi 2015 年 6 月 2 日
Stephen, thank you so much!!!! It worked! What happened before is that if I used xslwrite with mixed data, then it didn't work and the ouptup was a spreadsheet with nothing inside. Thank you very much again! Best,
Mauro
Stephen23
Stephen23 2015 年 6 月 2 日
Strange, as xlswrite should work with mixed data (it states this explicitly in the documentation). Can you show exactly how it was being used? It would be interesting to see the data (either upload a .mat file or as text within a comment).

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by