How to split letters in a word into an array
82 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ex: In the word 'HELLO', extract the letters 'H' 'E' 'L' 'L' 'O'
0 commentaires
Réponse acceptée
Jan
le 1 Juil 2013
The string 'Hello' consists of single characters already:
str = 'Hello';
for k = 1:length(str)
disp(str(k))
end
So please explain the wanted type and dimensions of the output. 'H' 'E' 'L' 'L' 'O' is not clear enough.
4 commentaires
Adam Danz
le 25 Mai 2021
☝ num2cell is the best solution. In case str is of class string
c = num2cell(char(str));
This works when str is a character array or a string.
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!