MATLAB Answers

How to split letters in a word into an array

조회 수: 202(최근 30일)
MKN
MKN 1 Jul 2013
Ex: In the word 'HELLO', extract the letters 'H' 'E' 'L' 'L' 'O'

  댓글 수: 0

로그인 to comment.

채택된 답변

Jan
Jan 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

Ronald D Smith
Ronald D Smith 7 Feb 2018
I've had a similar question a few times - my goal is take a string that represents RNA, e.g. seq = 'ATTAGCTG', and then use the individual letters as the xticklabels in a figure. cellstr(seq) would return a cell containing the entire string. I believe what I'm looking for is a cell array of individual letters (no loops would be nice). Forgive me if I'm missing something simple.
Ronald D Smith
Ronald D Smith 7 Feb 2018
Nevermind! I just noticed the transpose in the below comment. Learn something new every day.
Stephen Cobeldick
Stephen Cobeldick 7 Feb 2018
Try num2cell

로그인 to comment.

More Answers (2)

Tom
Tom 1 Jul 2013
Tom 님이 편집함. 1 Jul 2013
str = 'HELLO';
cellstr(str')'

  댓글 수: 0

로그인 to comment.


Octa
Octa 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

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그

제품


Translated by