How to change alphabet matrix to integer matrix?
Show older comments
matrix = ['AADBC';'CADBC';'BACAC']
I have the above 3x5 character matrix. I would like to convert it to a number matrix where A=1, B=2... etc.
I tried:
matrix = ['AADBC';'CADBC';'BACAC'];
zboom = zeros(size(matrix));
zboom(matrix=='A') = 1;
zboom(matrix=='B') = 2;
zboom(matrix=='C') = 3;
zboom(matrix=='D') = 4
But is there a more efficient way to do this? What if I want it to be able to go up to all 26 alphabets? Is there a formula for it? Thank you.
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!