Z = {'A'; 'B'; 'C'};
Z=regexprep(Z,'A','1');
Z=regexprep(A,'B','2'开发者_Go百科);
Z=regexprep(A,'C','3');
xlswrite('data.xls', A);
the data in the data.xls become 49 50 51. why the data is not 1 2 3?
This should probably read:
Z = {'A'; 'B'; 'C'};
Z=regexprep(Z,'A','1');
Z=regexprep(Z,'B','2');
Z=regexprep(Z,'C','3');
xlswrite('data.xls', Z);
Note the Z
s in the last 3 lines where you have A
s.
First, fix your code as PengOne points out. Second, note that 49, 50, and 51 are the Unicode (and ASCII) codes for the characters '1', '2', and '3'. When you pass an array of type char
to xlswrite
, it writes out the Unicode values for the characters in that array. You can use cellfun and str2num to convert all the elements of the cell to numbers like this:
Z1 = cellfun(@str2num, Z);
Then pass Z1
to xlswrite
instead of Z
.
精彩评论