MATLAB Answers

Help with splitting a string into a character array.

205 ビュー (過去 30 日間)
Benjamin Carpenter
Benjamin Carpenter 2017 年 11 月 5 日
Commented: Benjamin Carpenter 2017 年 11 月 5 日
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 2017 年 11 月 5 日
編集済み: Mischa Kim 2017 年 11 月 5 日
You could use
s = 'Potato';
t = num2cell(s)
t =
1×6 cell array
{'P'} {'o'} {'t'} {'a'} {'t'} {'o'}

  1 件のコメント

Benjamin Carpenter
Benjamin Carpenter 2017 年 11 月 5 日
Thank you!

サインイン to comment.

More Answers (0)

サインイン してこの質問に回答します。

タグ


Translated by