0

suppose i have an array (in matlab) like this :

A = [ 1 1 1 3 6 2 2 2 3 4 3 3];

i want another array suppose X to be an array containing those elements of A that are more than 3 in count e.g. X should be [1 2 3]

is there a function that can do this for me? if so what is it?

hj-007
  • 332
  • 3
  • 6
  • 16
  • 2
    Try http://stackoverflow.com/questions/2880933/how-can-i-count-the-number-of-elements-of-a-given-value-in-a-matrix for a number of techniques to count elements in a matrix. It's trivial to extend the given solutions so that you get a report of those elements occuring at least three times. – Li-aung Yip Aug 18 '13 at 16:35

1 Answers1

3

This will do it using unique and histc:

A = [1 1 1 3 6 2 2 2 3 4 3 3];
u = unique(A);
X = u(histc(A,u)>=3)

which returns

X =

   1     2     3
horchler
  • 18,384
  • 4
  • 37
  • 73