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 how many times each set of number occurs

Subject: count how many times each set of number occurs

From: Jemma Geoghegan

Date: 18 Aug, 2010 01:22:06

Message: 1 of 5

Suppose I have an output which is a vector containing 4 numbers, which is set to loop 5 times eg.

Ans =
1 2 3 4
1 2 3 4
5 6 7 8
1 2 3 4
5 6 7 8

I need a function to count how many times each set of number occurs
eg.
1 2 3 4 occurs 3 times
5 6 7 8 occurs 2 times

Thanks!

Subject: count how many times each set of number occurs

From: Matt Fig

Date: 18 Aug, 2010 01:33:05

Message: 2 of 5

A = [1 2 3 4
1 2 3 4
5 6 7 8
1 2 3 4
5 6 7 8];

[G,H,K] = unique(A,'rows');
C = histc(K,1:numel(H))

Now look at G and C.

Subject: count how many times each set of number occurs

From: J G

Date: 18 Aug, 2010 01:57:04

Message: 3 of 5

Thanks that's great but that only works when the output is a matrix, whereas mine is a vector which is repeated in a loop. Any suggestions?

Subject: count how many times each set of number occurs

From: Matt Fig

Date: 18 Aug, 2010 02:42:07

Message: 4 of 5

So let me get this straight.
You give an example of what you need that really is not at all an example of what you need? So how is anybody supposed to guess what it is that you really need, given that any example you give may or may not show what it is that you need?

Even with the above difficulties, I will guess that you should still use HISTC and maybe UNIQUE together.

Subject: count how many times each set of number occurs

From: Grzegorz

Date: 18 Aug, 2010 09:00:27

Message: 5 of 5

I had not noticed this thread, so I put my answer here:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/289564

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