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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by