convert alphabet to coresponding number by using ASCII

5 ビュー (過去 30 日間)
Maria
Maria 2020 年 5 月 25 日
回答済み: Walter Roberson 2020 年 5 月 25 日
I have question, how to convert alphabet in lowercase to coresponding number by using ASCII. Such as a=1,b=2,c=3...

採用された回答

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

その他の回答 (1 件)

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by