Frequency of elements in matrix - Matlab

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 14:09:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!