matlab 统计直方图

来源:百度知道 编辑:UC知道 时间:2024/08/22 10:33:43
请问在matlab里面,对数据进行频数统计是用hist和histc吧,我用一个数据少的矩阵试了一下,这两个好像一样的结果,但是对于数量较多的矩阵,结果不一样,应该是不同的,查资料,有人说hist是频数计算或频数直方图,histc是端点定位频数直方图,高手告诉我他们的区别?怎么用?有源代码吗?
我用hist统计几个范围内的数据的分布,比如,统计a=[1 2 4 5 6 7 2 4 2 8]中几个范围中的数的个数,处在1~3(包括1和3,下同)之间的数的个数为4,处在4~6之间的数的个数为4,处在7~9之间的数的个数为2,把图画出来,横坐标的数据是位于长矩形方块的中央,但是我的横坐标应该是一个范围的两端啊,难道histc可以解决?但是试不出来,没出现图形。还是用别的函数看?
那位大侠知道,告诉小弟一声啊,麻烦了,所以给出较高的奖分!

hist(x,M):将x封装在M个等距的区间(默认M=10)
histc(x,edges):落入edges元素之间的x值的个数
y=[-3,-2,-1,1,3];
x = -2.9:0.5:2.9;
histc(x,y)
n=hist(x)
n=hist(x,4) %这种情况建议用histc()

我不知道你能不能看懂英文,因为Help里面的解释真的非常清楚:

n = hist(Y) bins the elements in vector Y into 10 equally spaced containers and returns the number of elements in each container as a row vector. If Y is an m-by-p matrix, hist treats the columns of Y as vectors and returns a 10-by-p matrix n. Each column of n contains the results for the corresponding column of Y.

n = histc(x,edges) counts the number of values in vector x that fall between the elements in the edges vector (which must contain monotonically nondecreasing values). n is a length(edges) vector containing these counts.