首页 > 其他分享 >matlab中histc的用法

matlab中histc的用法

时间:2022-11-27 18:45:30浏览次数:68  
标签:25 binranges ages 用法 75 matlab ind histc bincounts

https://blog.csdn.net/weixin_41107577/article/details/103594881

定义矩阵:

ages = [3,12,24,15,5,74,23,54,31,23,64,75];

binranges = [0,10,25,50,75];

[bincounts,ind] = histc(ages,binranges);

输出为:

bincounts = [2,5,1,3,1];

ind = [1,2,2,2,1,4,2,4,3,2,4,5];

 

 

 

其中binranges代表了5个区间,分别为[0,10),[10,25),[25,50),[50,75),[75,无穷大)。

bincounts返回的是ages分别在这5个区间中所占的元素个数:

区间

元素个数

[0,10)

bincounts(1) = 2

[10,25)

bincounts(2) = 5

[25,50)

bincounts(3) = 1

[50,75)

bincounts(4) = 3

[75,无穷大)

bincounts(5) = 1

ind存储了ages中的每个元素分别在binranges的那个区间中,例如:

ages(1)在binranges的第1个区间中,所以ind(1) = 1;

ages(2)在binranges的第二个区间中,所以ind(2) = 2;

以此类推得ind矩阵。

标签:25,binranges,ages,用法,75,matlab,ind,histc,bincounts
From: https://www.cnblogs.com/focus-z/p/16930306.html

相关文章