根据数据集获取概率密度图像和概率分布图像

matlab代码如下:

number=10000
data=randn(number,1);
[y,x]=hist(data,100);         %分为100个区间统计,(你可以改你需要的区间数)

% y=y/length(data)/mean(diff(x));   %计算概率密度 ,频数除以数据种数,除以组距
y=y/number
figure(1)
bar(x,y,1);                      %用bar画图,最后的1是画bar图每条bar的宽度,默认是0.8所以不连续,改为1就可以了
%以上代码参考链接:https://zhidao.baidu.com/question/937150108990922492.html
%---------------------------------------------------------------------------------------------------
figure(2)
cdfplot(data)%参考链接:https://www.mathworks.com/help/stats/cdfplot.html



以上代码是分别画出data的概率密度(其实就是直方图)和概率分度。

猜你喜欢

转载自blog.csdn.net/appleyuchi/article/details/80953692