MATLAB Answers


Help with splitting a string into a character array.

Benjamin Carpenter さんによって質問されました 2017 年 11 月 5 日
最新アクティビティ 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
%identify length of 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.


1 件の回答

Mischa Kim
Answer by Mischa Kim
on 5 Nov 2017
Edited by Mischa Kim
on 5 Nov 2017
 Accepted Answer

You could use
s = 'Potato';
t = num2cell(s)
t =
1×6 cell array
{'P'} {'o'} {'t'} {'a'} {'t'} {'o'}

  1 件のコメント

サインイン to comment.

Translated by