MATLAB Answers

MKN
0

How to split letters in a word into an array

MKN
さんによって質問されました 2013 年 7 月 1 日
最新アクティビティ Stephen Cobeldick
さんによって 編集されました 2018 年 2 月 7 日
Ex: In the word 'HELLO', extract the letters 'H' 'E' 'L' 'L' 'O'

  0 件のコメント

サインイン to comment.

タグ

製品

3 件の回答

Jan
Answer by Jan
on 1 Jul 2013
 Accepted Answer

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 件のコメント

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.
Nevermind! I just noticed the transpose in the below comment. Learn something new every day.

サインイン to comment.


Tom
Answer by Tom
on 1 Jul 2013
Edited by Tom
on 1 Jul 2013

str = 'HELLO';
cellstr(str')'

  0 件のコメント

サインイン to comment.


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

  0 件のコメント

サインイン to comment.



Translated by