矩阵中元素的频率-Matlab [英] Frequency of elements in matrix - Matlab

查看:265
本文介绍了矩阵中元素的频率-Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我在Matlab中运行的函数中,我得到225x400的矩阵.我想计算此矩阵中每个元素的频率,这意味着我需要计算每个元素出现在矩阵上的次数.我的矩阵名称是"Idiff"

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"

我正在使用:

B=unique(Idiff);

在Idiff矩阵中查找唯一元素.我收到一列包含1138个元素的列,因此我知道这些元素是唯一的,并且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.

现在,我尝试使用以下方法计算每个唯一元素出现在Idiff矩阵中的次数:

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

C=histc(Idiff,B);

但是我得到的是一列47761个元素,我感到困惑.

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

你能帮我吗?

推荐答案

使用

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

否则,histc分别在每个列上运行.

Otherwise histc runs on each column separately.

这篇关于矩阵中元素的频率-Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆