MATLAB: Convert character matrix to numeric matrix

arraycharcharacterdoubleMATLABmatrixnumeric

Hello
I have this matrix:
A=['AB' 'AC';'AD' 'AE'];
I want to make each element of this words to have unique value of number. After that I want a code to transfer the numbers to the origin words.
I used this code:
A=['AB' 'AC';'AD' 'AE'];
A = double(A)
A = char(A)
The problem is that the output has the size 2*4 while it should be as the input 2*2 this due to that matlab deals with the letters not the words so it make each letter in separate column.
Please help me.
Thanks

Best Answer

If you really need a 2x2 array then one straightforward way would be to use a cell array:
>> A = {'AB','AC';'AD','AE'}
A =
'AB' 'AC'
'AD' 'AE'
>> B = cellfun(@double,A,'uni',0)
B =
[65,66] [65,67]
[65,68] [65,69]
>> C = cellfun(@char,B,'uni',0)
C =
'AB' 'AC'
'AD' 'AE'