Find ascii numbers from cells
2 visualizaciones (últimos 30 dÃas)
Mostrar comentarios más antiguos
Ivan Mich
el 23 de En. de 2021
Comentada: Ivan Mich
el 24 de En. de 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 comentarios
Respuesta aceptada
Adam Danz
el 23 de En. de 2021
Editada: Adam Danz
el 23 de En. de 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 comentarios
Adam Danz
el 23 de En. de 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}
Más respuestas (0)
Ver también
CategorÃas
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!