MATLAB: Convert string to cell array

cell arraysstring

How to convert string
a b 3
into cell array {'a' 'b' 3}

Best Answer

Artyom - try using textscan to read the data from the string. Something like
str = 'a b 3';
Z = textscan(str,'%s','Delimiter',' ')';
Z{:}'
ans =
'a' 'b' '3'
We use the fact that each character in he input string, str, is separated by a space. The space then acts as the delimiter between each character which we can use to separate each into its own string.
Note that Z is a 3x1 cell array.
Try the above and see what happens!