How to count the number of occurances of a specifc sample?
1 view (last 30 days)
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
0 Comments
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
See Also
Categories
Find more on Waveform Generation 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!