How to count the number of occurances of a specifc sample?

1 view (last 30 days)
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
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
Hunter on 19 Jun 2014
When Nan is in y, the instrument failed to pick up data. I would need the program just not read the Nan's. so for example if x= [ . . . Feb.2, Feb.3, Feb. 4, . . .] and y is [. . . 1, Nan, 0,. . .]
I would like the result to read x=[. . ., Feb.2, Feb.4,. . .] & y =[. . ., 1,0, . . .]

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!