필터 지우기
필터 지우기

How to split letters in a word into an array

조회 수: 81 (최근 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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by