MATLAB: Reading a CSV file with XLSread, convert raw data to strings

cellarrayxlsread

How do I convert this cell array to a char array (obtained by reading in from a csv file using xlsread and the "raw" argument
A =
[ 1]
[ 2]
[ 3]
'Y'
[ 5]
[ 6]
[ 7]
'Y'
'X'
[ 9]
[10]
I need to output this to a text file and have used:
for row = 1:numel(A)
fprintf(fileID,'%s\n',A{row});
end
but I get strange characters:

Best Answer

Given a cell array of mixed numeric and string data:
>> A = {1;2;3;'Y';5;6;7;'Y';'X';9;10};
convert to a cell array of strings using cellfun and num2str (which ignores the strings):
>> B = cellfun(@num2str,A, 'UniformOutput',false)
B =
'1'
'2'
'3'
'Y'
'5'
'6'
'7'
'Y'
'X'
'9'
'10'
And convert a cell array of strings to a pure character array by wrapping this in char:
>> char(B)
ans =
1
2
3
Y
5
6
7
Y
X
9
10