convert alphabet to coresponding number by using ASCII

5 vues (au cours des 30 derniers jours)
Maria
Maria le 25 Mai 2020
I have question, how to convert alphabet in lowercase to coresponding number by using ASCII. Such as a=1,b=2,c=3...

Réponse acceptée

Ameer Hamza
Ameer Hamza le 25 Mai 2020
Like this
char2num = @(c) char(c)-96;
Example
>> char2num('a')
ans =
1
>> char2num('b')
ans =
2
>> char2num('z')
ans =
26

Plus de réponses (1)

Walter Roberson
Walter Roberson le 25 Mai 2020
UpperToLower = @(c) char(c-'A'+'a')
Or if you are daring,
UpperToLower = @(c) char(c+32);

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by