MATLAB Answers

How to split letters in a word into an array

430 views (last 30 days)
MKN
MKN on 1 Jul 2013
Edited: Stephen Cobeldick on 7 Feb 2018
Ex: In the word 'HELLO', extract the letters 'H' 'E' 'L' 'L' 'O'

Accepted Answer

Jan
Jan on 1 Jul 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.
  3 Comments

Sign in to comment.

More Answers (2)

Tom
Tom on 1 Jul 2013
Edited: Tom on 1 Jul 2013
str = 'HELLO';
cellstr(str')'

Octa
Octa on 2 Jul 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

Tags

Products

Community Treasure Hunt

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

Start Hunting!