3

From a function that i run in matlab i get a 225x400 matrix. I want to count the frequency of each element in this matrix, meaning that i need to calculate how many times each elements appears on the the matrix. My matrix name is "Idiff"

I am using:

B=unique(Idiff);

to find the unique elements in the Idiff matrix. I receive a column of 1138 elements, so i understand that these elements are unique and all the other elements in the Idiff matrix are these elements repeated.

Now i try to count how many times each unique element appears in my Idiff matrix by using:

C=histc(Idiff,B);

But what i get is a column of 47761 elements and i get confused.

Can you help me?

astralreb
  • 37
  • 1
  • 3
  • 7
  • possible duplicate of [find count of elements in a matrix of two columns](http://stackoverflow.com/questions/11139447/find-count-of-elements-in-a-matrix-of-two-columns) – Andrey Rubshtein Jun 27 '12 at 12:48

1 Answers1

1

Use

C=histc(Idiff(:),B);

Otherwise histc runs on each column separately.

Yanai Ankri
  • 439
  • 4
  • 11
  • Great that worked! Now if i want to create the probability of each unique element meaning that i have to calculate this probability of each element=number of occurances/total occurances how can i make this in matlab? – astralreb Jun 27 '12 at 13:48