how to covert char array to num array?

11 vues (au cours des 30 derniers jours)
Mithushan Kanthasamy
Mithushan Kanthasamy le 22 Fév 2021
Commenté : Walter Roberson le 23 Fév 2021
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 commentaires
Stephen23
Stephen23 le 23 Fév 2021
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 le 23 Fév 2021
The original version had 'the' instead of 'thee' so it could not be represented as a character array... which is why David answered with {}

Connectez-vous pour commenter.

Réponse acceptée

David Hill
David Hill le 22 Fév 2021
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 commentaires
Mithushan Kanthasamy
Mithushan Kanthasamy le 22 Fév 2021
is there way to convert it without for loop?
Walter Roberson
Walter Roberson le 22 Fév 2021
No. The best you can do is hide the loop
output = cellfun(@double, arr, 'uniform', 0)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by