Find ascii numbers from cells
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Adam Danz
on 23 Jan 2021
Edited: Adam Danz
on 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 Comments
Adam Danz
on 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}
More Answers (0)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!