Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

converting string code into numbers?

조회 수: 3 (최근 30일)
Benjamin Trivers
Benjamin Trivers 2020년 1월 26일
마감: MATLAB Answer Bot 2021년 8월 20일
Write a function m-file called stringcode that takes a string as input and produces an array containing a code for each letter in the string with A = 0, B = 1, ..., Z = 25 and all other characters getting the value 26
Hints
  • Convert the string to all upper case (using the command upper).
  • Convert the string to an array of ascii codes (use double).
  • Loop through the array and change the codes to the right values. Look up the codes for ’A’ and ’Z’.
here is my code
function num = stringcode( word )
asc = double(upper(word))
if asc >= 33 & asc <=47 & asc < 0
asc = 26
else asc = double(upper(word))
end
% simple arithmetic
num = asc - double('A')
end
I cant get the special characters to come up as the number 26
  댓글 수: 4
Walter Roberson
Walter Roberson 2020년 1월 28일
The homework requires that a loop be used.
Rik
Rik 2020년 1월 28일
Also, you need to use a single pipe character for an array, so that second line doesn't work.

답변 (0개)

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by