Tyler
Posts:
78
Registered:
7/20/08
|
|
Is there a better way to count number of occurances of string when grouping?
Posted:
Mar 20, 2012 2:15 PM
|
|
Hi everyone:
I have a dataset svdatm with columns:
% dnum (datenum) % symid (symbol id - a cell array)
I would like to find the count or number of elements (i.e., symid) that occur each day.
% Use a loop - this becomes slow for large array mydates = unique(svdatm.dnum); NDAYS = length(mydates); symcount = nan(NDAYS,1); for i = 1:NDAYS idxDay = svdatm.dnum==mydates(i); tmpD = svdatm(idxDay,:); symcount(i) = length(unique(tmpD.symid)); end
I've tried to speed up the process using something like the following,
symcount = unstack(svdatm,'symid','dnum','AggregationFun',@numel);
or similarly grpstats, but these all bomb because it is a cell array I am applying the function too. Is there a better way to do this?
Cheers,
t.
|
|