convert alphabet to coresponding number by using ASCII
5 次查看(过去 30 天)
显示 更早的评论
I have question, how to convert alphabet in lowercase to coresponding number by using ASCII. Such as a=1,b=2,c=3...
0 个评论
采纳的回答
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
0 个评论
更多回答(1 个)
Walter Roberson
2020-5-25
UpperToLower = @(c) char(c-'A'+'a')
Or if you are daring,
UpperToLower = @(c) char(c+32);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!