简体   繁体   中英

Frequency of elements in matrix - Matlab

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?

Use

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

Otherwise histc runs on each column separately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM