MATLAB实现频数直⽅图——hist的使⽤
"hist" is short for "Histogram(直⽅图、柱状图)"。
1.N = hist(Y)
bins the elements of Y into 10 equally spaced containers and returns the number of elements in each . If Y is a matrix, hist works down the columns.
(将向量Y的元素平均分到⼗个等间隔的容器中,并且返回每个容器的元素个数。如果Y是⼀个矩阵,hist指令逐列元素操作。Y为向量的情形见例1和2,为矩阵的情形见例3.)
例1.执⾏指令
>> Y = [1:10];
>> hist(Y)
得到
matlab直方图10个蓝⾊⽅条,每个⽅条对应⼀个容器,其长度代表容器中数据的多少。由图知,容器中的数据量均为
1。这个例⼦不够典型,见例2.
例2.执⾏指令
>> Y = [1, 2, 2, 5, 6, 6, 8, 11];
>> hist(Y)
得到
Y最⼤为11,最⼩为1,故⽽将区间[1,11]均分为10分,分别为[1, 2], (2,3], (3,4], (4,5], (5,6], (6,7], (7,8], (8,9], (9,10], (10,11].
例3.当Y是矩阵时的情况。
执⾏指令:
>> Y = [1,2.5,2.1;3,3.5,6];
>> hist(Y)
注意,Y为矩阵:
1.0000
2.5000 2.1000
3.0000 3.5000 6.0000
Y有三列元素,逐列元素产⽣对应的直⽅图。得到
观察此图和矩阵Y,由于Y的元素最⼤为1,最⼩为6,故⽽将区间[1,6]以0.5的间隔划分为10个等长的⼦区间作为10个容器去容纳数据。图中有三种颜⾊的⽅条:蓝⾊,绿⾊和红⾊,分别对应Y中的第1,2,3列元素。如第⼀列元素为1和3,故⽽区间[1,1.5]和(2.5,3]中有蓝⾊⽅条。2.N = hist(Y,M)
where M is a scalar, uses M bins.(M是⼀个标量,表明使⽤M个箱⼦)
例1.执⾏指令
>> Y = [1, 1, 1.3, 2.6, 3, 3.4, 5, 5.9, 6, 6,1, 7, 7,2];
>> hist(Y, 6)
得到
3.N = hist(Y,X)
where X is a vector, returns the distribution of Y among bins with centers specified by X.(X是向量,以X中的元素为区间中⼼可获得⼀系列区间,执⾏命令可获得Y在这些区间中的分布情况。) The first bin includes data between -inf and the first center and the last bin includes data between the last bin and inf. Note: Use HISTC if it is more natural to specify bin edges instead.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论