Borrar filtros
Borrar filtros

How to split letters in a word into an array

17 visualizaciones (últimos 30 días)
MKN
MKN el 1 de Jul. de 2013
Editada: Stephen23 el 26 de Mayo de 2021
Ex: In the word 'HELLO', extract the letters 'H' 'E' 'L' 'L' 'O'

Respuesta aceptada

Jan
Jan el 1 de Jul. de 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 comentarios
Stephen23
Stephen23 el 7 de Feb. de 2018
Editada: Stephen23 el 26 de Mayo de 2021
Try num2cell, e.g. where W is your word (a 1xN character vector):
C = num2cell(W(:))
Adam Danz
Adam Danz el 25 de Mayo de 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.

Iniciar sesión para comentar.

Más respuestas (2)

Tom
Tom el 1 de Jul. de 2013
Editada: Tom el 1 de Jul. de 2013
str = 'HELLO';
cellstr(str')'

Octa
Octa el 2 de Jul. de 2013
If you want to extract the letters, simply extract in this way
>> str(1)
H
>> str(2)
E
>> str(3)
L
>>str(4)
L
>> str(5)
L
>> str(6)
O

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by