MATLAB Answers

Help with splitting a string into a character array.

조회 수: 243(최근 30일)
Let's say I have a string s='Potato'.
How would I split that up into an array so that it looks like t='P, o, t, a, t, o'?
I'm currently doing it like this:
%%Choose word
word=datasample(wordbank,1)
%identify length of word
wordlength=strlength(word)
sol = split(word,"")
The only problem with doing it this way is that there are two blank spots and the beginning and end of the character array. It looks like this when outputted:
"" "P" "o" "t" "a" "t" "o" ""
How can I split it so that the blank values at the beginning and end aren't there?

  댓글 수: 0

로그인 to comment.

채택된 답변

Mischa Kim
Mischa Kim 5 Nov 2017
Mischa Kim 님이 편집함. 5 Nov 2017
You could use
s = 'Potato';
t = num2cell(s)
t =
1×6 cell array
{'P'} {'o'} {'t'} {'a'} {'t'} {'o'}

  댓글 수: 1

로그인 to comment.

More Answers (0)

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

태그


Translated by