How to split letters in a word into an array

73 ビュー (過去 30 日間)
MKN
MKN 2013 年 7 月 1 日
編集済み: Stephen23 2021 年 5 月 26 日
Ex: In the word 'HELLO', extract the letters 'H' 'E' 'L' 'L' 'O'

採用された回答

Jan
Jan 2013 年 7 月 1 日
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 件のコメント
Stephen23
Stephen23 2018 年 2 月 7 日
編集済み: Stephen23 2021 年 5 月 26 日
Try num2cell, e.g. where W is your word (a 1xN character vector):
C = num2cell(W(:))
Adam Danz
Adam Danz 2021 年 5 月 25 日
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.

サインインしてコメントする。

その他の回答 (2 件)

Tom
Tom 2013 年 7 月 1 日
編集済み: Tom 2013 年 7 月 1 日
str = 'HELLO';
cellstr(str')'

Octa
Octa 2013 年 7 月 2 日
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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by