MATLAB Answers

How to assign numbers to letters of the alphabet. Ex. A/a=1 B/b=2

11 views (last 30 days)
Orion Sun
Orion Sun on 18 Jan 2020
Edited: Vladimir Sovkov on 18 Jan 2020
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 Comments

Sign in to comment.

Answers (2)


Vladimir Sovkov
Vladimir Sovkov on 18 Jan 2020
Edited: Vladimir Sovkov on 18 Jan 2020
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 Comments

Sign in to comment.

Sign in to answer this question.

Tags


Translated by