How to change alphabet matrix to integer matrix?
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!