Reputation: 20633
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?
Upvotes: 4
Views: 11144
Reputation: 74930
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'
Upvotes: 5
Reputation: 9317
For your specific example try:
cellstr(strread('A, B, C, D','%c,'))'
Upvotes: 3