Splitting Cell Arrays by Delimiter
Show older comments
So I have a large data set stored in a 4699x1 cell. Each row has a different number of string items separate by commas. Is there any way to count how many items there are in each row? For example, with these rows, I would like a 4699x1 cell that is 3,4,1,1,2,2,2,1,1,1,4,etc...

Accepted Answer
More Answers (1)
There is no need to split, just count the commas, e.g.:
>> s = {'AAAA,BBBB'; 'CCCC,DDDD,EEEE'; 'FFFF'};
>> n = 1+cellfun(@numel,strfind(s,','))
n =
2
3
1
or
>> n = 1+cellfun(@(v)nnz(v==','),s)
n =
2
3
1
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!