How to convert comma-separated string to cell array of strings in matlab

matlab

Solution

Here's a solution that will cut up the string at commas, semicolons, or white spaces, and that will work for strings of any length

string = 'A, BB, C'

tmp = regexp(string,'([^ ,:]*)','tokens');
out = cat(2,tmp{:})


out = 

    'A'    'BB'    'C'

Problem

I have following string 'A, B, C, D' from which I want to make a cell array such as { 'A', 'B', 'C', 'D' } How would I be able to do this in Matlab?

Original source