How to assign numbers to letters of the alphabet. Ex. A/a=1 B/b=2
6 次查看(过去 30 天)
显示 更早的评论
As the title stated. I need to write a function where the input of a certain letter will give me the output of its corresponding number. (based off ASCII table)
Ex. someFunction (A)
ans = 1
someFunction (f)
ans = 6
Thanks for the help in advanced!
0 个评论
回答(2 个)
Vladimir Sovkov
2020-1-18
编辑:Vladimir Sovkov
2020-1-18
The ASCII codes can be found with the function double
double('A');
65
If you want to get its ordinal number in the alphabet, use something like
k=double('A');
if k>64 && k<91
k=k-64;
elseif k>96 && k<123
k=k-96;
else
disp('not a letter')
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!