MATLAB的 histfit 函数,可以简单、粗暴的得到数据的柱状图和拟合曲线。而图形对应的数据可以利用get函数获得!
举例如下:
r = normrnd(10,1,100,1); % 生成随机数
figure
hf=histfit(r,20); % 20表示将数据均分为20段
pd = fitdist(r,'Normal') % 获得拟合曲线的参数,均值和标准差,r必须要列向量,否则会报错!!!
get(hf(1)) % properties of the histogram
get(hf(2)) % properties of the normal curve
% 柱状图数据
x1=get(hf(1),'XData');
y1=get(hf(1),'YData');
% 拟合曲线数据
x2=get(hf(2),'XData');
y2=get(hf(2),'YData');
figure
subplot(211)
bar(x1,y1)
subplot(212)
plot(x2,y2)
Excel画柱状图和PDF
Excel2019画正态分布图和正态曲线组合图_田公子Zzz的博客-CSDN博客_正态分布图怎么画