How to convert characters array into integer number array
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I have a text file in which all the contents are characters like a,b,c,d…z . Can somone explain how to convert theses alphabets in txt file into numbers like a corresponds to1, b corresponds to 2 ,in the converted file.
Thanks.
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2014년 4월 9일
str='I have a text file in which all the contents are characters like a,b,c,d…z . Can somone explain how to convert theses alphabets in txt file into numbers like a corresponds to1, b corresponds to 2 ,in the converted file'
s='a':'z'
for k=1:numel(s)
str=regexprep(str,s(k),num2str(k),'ignorecase');
end
str
댓글 수: 5
Azzi Abdelmalek
2014년 4월 9일
fid = fopen('change.txt');
str= textscan(fid,'%s');
fclose(fid)
str=str{:}
s='a':'z'
for k=1:numel(s)
str=regexprep(str,s(k),num2str(k),'ignorecase');
end
str
추가 답변 (1개)
Walter Roberson
2014년 4월 9일
converted_to_numbers = characters - 'a' + 1;
Then it is just a matter of writing out the numbers as text, which you already know how to do.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!