Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Count the number occurence

Subject: Count the number occurence

From: Alex

Date: 4 Nov, 2010 13:19:04

Message: 1 of 4

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

Subject: Count the number occurence

From: dpb

Date: 4 Nov, 2010 13:21:49

Message: 2 of 4

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

--

Subject: Count the number occurence

From: ImageAnalyst

Date: 4 Nov, 2010 13:27:19

Message: 3 of 4

Alex:
You're looking for hist() or histc(), or possibly imhist().
You want to calculate the histogram of the data.
-ImageAnalyst

Subject: Count the number occurence

From: Roger Stafford

Date: 4 Nov, 2010 18:00:08

Message: 4 of 4

"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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us