I'm trying to decipher a text file full of lowercase characters. First I have to convert the characters to 27 numbers (1 for each letter and 27=space) using "double". Can you guys help me code:
1. a "function" which converts any text file with 27 unique characters (including space) into a string of 27 unique numbers? I have to use "double" to convert to ASCII first, and then convert the 26 lowercase letters and space into 1:27
ex: function('hello')=[8 5 12 12 15]
2. a "function" that reverses the process, using "char"?
ex: functioninverse([8 5 12 12 15])=hello

 채택된 답변

Walter Roberson
Walter Roberson 2015년 10월 4일

0 개 추천

[~, idx] = ismember( tolower(TheTextString), ['a' : 'z', ' ']);
result = double(idx);

댓글 수: 4

Erik Lee
Erik Lee 2015년 10월 5일
Thanks! How can I reverse this so char(result)=thetextstring?
str = ['a' : 'z', ' '];
RecalledString = str(result);
Erik Lee
Erik Lee 2015년 10월 5일
The assignment said I have to use "char" to reverse "double"
str = 0 + ['a' : 'z', ' '];
RecalledString = char(str(result));

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2015년 10월 4일

댓글:

2015년 10월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by