Find ascii numbers from cells
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ivan Mich
am 23 Jan. 2021
Kommentiert: Ivan Mich
am 24 Jan. 2021
I would like to find ascii numbers from cells. My file has words/letters (cell arrays). I would like to calculate ascii number for each cell.
Could you help me please?
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 23 Jan. 2021
Bearbeitet: Adam Danz
am 23 Jan. 2021
Matlab stores characters as Unicode characters which incorporates the ASCII character set as the first 128 sumbols.
Convert characters -->Unicode/ASCII using double('__')
Convert Unicode/ASCII-->characters using char(__)
double('a')
double('Matlab')
char([77 97 116 108 97 98])
double('😎') % Not ASCII
To apply that to a cell array,
z = {'Here','is an','example','!',''};
a = cellfun(@double, z, 'UniformOutput', false)
a{1} % "Here"
a{2} % "is an"
--or--
v = cell2mat(cellfun(@double, z, 'UniformOutput', false))
Put the cell array of ASCII codes back into char vector
c = strjoin(cellfun(@char, a, 'UniformOutput', false))
3 Kommentare
Adam Danz
am 23 Jan. 2021
How are you reading in the file
C = readcell('names.xlsx');
a = cellfun(@double, C, 'UniformOutput', false)
% a =
% 7×1 cell array
% {1×4 double}
% {1×6 double}
% {1×6 double}
% {1×4 double}
% {1×4 double}
% {1×3 double}
% {1×7 double}
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!