How to count the number of occurances of a specifc sample?
Show older comments
In my data set, I have two columns (a date, and another one that has a value of either 0 or 1). There are dates that are repeated, so the actual set looks something like this:
x= [Jan. 1, Jan. 1, Jan.1, Jan.2, Jan.2, Jan.3. . .] y= [ 1 , 0 , 1 , 1 , 1 , 0. . .]
How do I ask Matlab to count these events for me? I wish to obtain a matrix in the form of: x=[ Jan. 1, Jan.2, Jan.3, . . . ] y=[ 2, 2, 0, . . . .]
Thanks for your help
Answers (1)
Azzi Abdelmalek
on 17 Jun 2014
x= {'Jan.1', 'Jan.1', 'Jan.1', 'Jan.2', 'Jan.2', 'Jan.3' 'Jan.3'}
y= [ 1 0 1 1 1 0 1 ]
z=x(logical(y))
[aa,bb,cc]=unique(z)
ii=histc(cc,1:numel(aa))
out=[aa; num2cell(ii')]
3 Comments
Hunter
on 17 Jun 2014
Azzi Abdelmalek
on 17 Jun 2014
When you have Nan in y, what action is needed?
Hunter
on 19 Jun 2014
Categories
Find more on NaNs 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!