问题
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?
回答1:
Use
C=histc(Idiff(:),B);
Otherwise histc runs on each column separately.
来源:https://stackoverflow.com/questions/11226474/frequency-of-elements-in-matrix-matlab