How to convert characters array into integer number array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Gova ReDDy
am 9 Apr. 2014
Kommentiert: Gova ReDDy
am 9 Apr. 2014
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 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 9 Apr. 2014
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 Kommentare
Azzi Abdelmalek
am 9 Apr. 2014
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
Weitere Antworten (1)
Walter Roberson
am 9 Apr. 2014
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 Kommentare
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!