Hello everyone,
I would like to count one number's occurrence
My data look like this
2
1
3
1
5
1
6
5
1
2
1
7
1
2
2
1
7
23
12
8
8
10
13
1
4
5
1
2
5
5
18
3
1252
and I would like to count how many times every number appears. I am looking for some already implemented function as I have to run this code for many data so code efficiency is really important.
I would like to thank you in advance for your help
Regards. Alex
|
|
0
|
|
|
|
Reply
|
Alex
|
11/4/2010 1:19:04 PM |
|
Alex wrote:
> Hello everyone,
> I would like to count one number's occurrence
....
> and I would like to count how many times every number appears. I am
> looking for some already implemented function ...
doc hist % or histc
--
|
|
0
|
|
|
|
Reply
|
dpb
|
11/4/2010 1:21:49 PM
|
|
Alex:
You're looking for hist() or histc(), or possibly imhist().
You want to calculate the histogram of the data.
-ImageAnalyst
|
|
0
|
|
|
|
Reply
|
ImageAnalyst
|
11/4/2010 1:27:19 PM
|
|
"Alex " <alaios@yahoo.com> wrote in message <iaubs8$399$1@fred.mathworks.com>...
> ...... and I would like to count how many times every number appears. ......
- - - - - - - - - -
If your data values are not necessarily integers, you can first do
[~,~,n] = unique(data)
and then use histc on the returned vector n to get your counts.
Roger Stafford
|
|
0
|
|
|
|
Reply
|
Roger
|
11/4/2010 6:00:08 PM
|
|