开发者

regexprep doubt in matlab

开发者 https://www.devze.com 2023-03-17 11:17 出处:网络
Z = {\'A\'; \'B\'; \'C\'}; Z=regexprep(Z,\'A\',\'1\'); Z=regexprep(A,\'B\',\'2\'开发者_Go百科); Z=regexprep(A,\'C\',\'3\');
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 Zs in the last 3 lines where you have As.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消