Consider

댓글 수: 1

I don't understand the examples. Why is J = 1, and K (the last/fourth letter) = 2??? And what kind of name is NOML, and how do you get the sequence 1,2,26, 25 for NOML? In the meantime, here are some helpful snippets:
vec = linspace('A', 'Z', 26)
name = 'Manav'
numbers = upper(name) - 'A' + 1
vec =
Columns 1 through 21
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
Columns 22 through 26
86 87 88 89 90
name =
'Manav'
numbers =
13 1 14 1 22

댓글을 달려면 로그인하십시오.

답변 (1개)

Sindar
Sindar 2020년 1월 21일

1 개 추천

I think the only change you need from Image Analyst's is to subtract off the (numeric code for the) first letter of the name, rather than the first letter of the alphabet, then ensure everything is positive.
name = 'Manav'
% get the numeric code for each letter, then shift so the first letter corresponds to 0
numbers = upper(name) - upper(name(1));
% map negatives to positive (e.g. -1 -> 26) and count from 1
numbers = mod(numbers,26) + 1;

댓글 수: 2

numbers = mod(numbers,26) + 1;
Close but not quite. Consider 26. mod(26,26) is 0, and you would add 1 to get 1, whereas you would want to leave 26 as 26. For that matter, consider 1: mod(1,26) is 1, add the +1 to get 2, instead of leaving it alone as 1.
Sindar
Sindar 2020년 1월 21일
That's why I don't add 1 in the line above. So, the first letter maps to 0, then mod(0,26)=0, then 1. While the letter before it maps to -1, then mod(-1,26)=25, then 26.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Package MATLAB Functions에 대해 자세히 알아보기

질문:

2020년 1월 21일

편집:

2020년 1월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by