matlab实现频率分布直方图

样本为i
I为样本平均值
横坐标要实现i/I
纵坐标为 频数/总样本数/子区间个数
具体如图。需要补充请回复我,急

img

麻烦写一下程序,谢谢


clc
clear
close all

x = randn(1000, 1);

% 画频率分布直方图
[counts,centers] = hist(x, 7);
figure
bar(centers, counts / sum(counts))

% 分布参数拟合
[mu,sigma]=normfit(x);

% 画已知分布的概率密度曲线
x1 = -4:0.1:4;
y1 = pdf('Normal', x1, mu,sigma);
hold on
plot(x1, y1)

clc,clear,close all
x = linspace(0,7,21);
y = exp(-0.6.*x);
bar(x,y,1)

img

使用hist函数先求频数分布直方图,然后缩放x轴和y轴。

代码如下:

I = randn(1000,1);  
h = 5;
[counts,centers] = hist(I,h);
centers=centers/mean(I);
counts=counts/sum(counts)/h;
bar(centers,counts);