MATLAB: Concatenate cell array with double matrix

cellconversionmatrix

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!

Best Answer

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