How to assign numbers to letters of the alphabet. Ex. A/a=1 B/b=2
조회 수: 9 (최근 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에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!