Find ascii numbers from cells

์กฐํšŒ ์ˆ˜: 4 (์ตœ๊ทผ 30์ผ)
Ivan Mich
Ivan Mich 2021๋…„ 1์›” 23์ผ
๋Œ“๊ธ€: Ivan Mich 2021๋…„ 1์›” 24์ผ
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?

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Adam Danz
Adam Danz 2021๋…„ 1์›” 23์ผ
ํŽธ์ง‘: Adam Danz 2021๋…„ 1์›” 23์ผ
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')
ans = 97
double('Matlab')
ans = 1ร—6
77 97 116 108 97 98
char([77 97 116 108 97 98])
ans = 'Matlab'
double('๐Ÿ˜Ž') % Not ASCII
ans = 1ร—2
55357 56846
To apply that to a cell array,
z = {'Here','is an','example','!',''};
a = cellfun(@double, z, 'UniformOutput', false)
a = 1x5 cell array
{1ร—4 double} {1ร—5 double} {1ร—7 double} {[33]} {0ร—0 double}
a{1} % "Here"
ans = 1ร—4
72 101 114 101
a{2} % "is an"
ans = 1ร—5
105 115 32 97 110
--or--
v = cell2mat(cellfun(@double, z, 'UniformOutput', false))
v = 1ร—17
72 101 114 101 105 115 32 97 110 101 120 97 109 112 108 101 33
Put the cell array of ASCII codes back into char vector
c = strjoin(cellfun(@char, a, 'UniformOutput', false))
c = 'Here is an example ! '
  ๋Œ“๊ธ€ ์ˆ˜: 3
Adam Danz
Adam Danz 2021๋…„ 1์›” 23์ผ
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}
Ivan Mich
Ivan Mich 2021๋…„ 1์›” 24์ผ
Thank you. I have one more question. I would like to use crosscorr funtion, in order to correlate each cell (to correlate cell 1st column with the cell in second column etc).
my code is
Pin = readcell('names_2.xlsx');
A = cellfun(@double, Pin, 'UniformOutput', false);
a=A(2:end,1);
b=A(2:end,2);
[c,lag]=crosscorr(a,b)
But command window shows me :
The value of 'y1' is invalid. Expected first input series to be one of these types:
double
Instead its type was cell.
Could you help me please?

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ถ”๊ฐ€ ๋‹ต๋ณ€ (0๊ฐœ)

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Data Type Conversion์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by