how to covert char array to num array?

조회 수: 13 (최근 30일)
Mithushan Kanthasamy
Mithushan Kanthasamy 2021년 2월 22일
댓글: Walter Roberson 2021년 2월 23일
how do i convert char array to num array?
arr = ['some'; 'thee'; 'time'; 'hour']
I need a way to convert into the ascii values of these char.
  댓글 수: 2
Stephen23
Stephen23 2021년 2월 23일
arr = ['some'; 'thee'; 'time'; 'hour']
arr = 4x4 char array
'some' 'thee' 'time' 'hour'
mat = double(arr)
mat = 4×4
115 111 109 101 116 104 101 101 116 105 109 101 104 111 117 114
Walter Roberson
Walter Roberson 2021년 2월 23일
The original version had 'the' instead of 'thee' so it could not be represented as a character array... which is why David answered with {}

댓글을 달려면 로그인하십시오.

채택된 답변

David Hill
David Hill 2021년 2월 22일
arr={'some'; 'the'; 'time'; 'hour'};%must be cell array since lengths are not the same
for k=1:length(arr)
arr{k}=double(arr{k});%simple for-loop converts
end
  댓글 수: 2
Mithushan Kanthasamy
Mithushan Kanthasamy 2021년 2월 22일
is there way to convert it without for loop?
Walter Roberson
Walter Roberson 2021년 2월 22일
No. The best you can do is hide the loop
output = cellfun(@double, arr, 'uniform', 0)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile 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