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!