Trying to make a function who says the position for a letter in the alphabet
3 views (last 30 days)
Show older comments
I can't figure out how to get this fuction to work. I need to use a letter as input, for example a, and the funkttion to return its position (1).
function h = postiton(a)
Alfabetet=['a';'b';'c';'d';'e';'f';'g';'h';'i';'j';'k';'l';'m';'n';'o';'p';'q';'r';'s';'t';'u';'v';'w';'x';'y';'z';];
h=find(Alfabetet==a))
end
How do i get this to work?
I want to write position(k) and get ans=11
0 Comments
Accepted Answer
Image Analyst
on 2 Apr 2014
Try this:
function test
aPosition = postiton('a')
function h = postiton(theLetter)
Alfabetet=['a';'b';'c';'d';'e';'f';'g';'h';'i';'j';'k';'l';'m';'n';'o';'p';'q';'r';'s';'t';'u';'v';'w';'x';'y';'z';];
h = find(ismember(Alfabetet, theLetter));
2 Comments
Image Analyst
on 2 Apr 2014
Not if it's a literal but you can if it's a variable, like this:
a = 'c'; % Whatever letter you want.
aPosition = postiton(a) % or position() - however you want to spell it.
More Answers (0)
See Also
Categories
Find more on Programming Utilities in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!