How to change alphabet matrix to integer matrix?
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!