MATLAB 帮助中心
本页翻译不是最新的。点击此处可查看最新英文版本。
具有分布拟合的直方图
histfit(data)
histfit(data,nbins)
histfit(data,nbins,dist)
histfit(ax,___)
h = histfit(___)
histfit(data) 绘制 data 中的值的直方图并拟合正态密度函数,直方图的 bin 个数等于 data 中元素个数的平方根。
data
示例
histfit(data,nbins) 使用 nbins 个 bin 绘制直方图,并拟合正态密度函数。
nbins
histfit(data,nbins,dist) 使用 nbins 个 bin 绘制直方图,并根据 dist 指定的分布拟合密度函数。
dist
histfit(ax,___) 使用 Axes 对象 ax 指定的绘图坐标区。将 ax 指定为第一个输入参量,后跟先前语法中的任何输入参量组合。
ax
Axes
h = histfit(___) 返回句柄向量 h,其中 h(1) 是直方图的句柄,h(2) 是密度曲线的句柄。
h
h(1)
h(2)
全部折叠
用均值 10 和方差 1 从正态分布生成大小为 100 的样本。
rng default; % For reproducibility r = normrnd(10,1,100,1);
构建具有正态分布拟合的直方图。
histfit(r)
histfit 使用 fitdist 对数据进行分布拟合。使用 fitdist 获得在拟合中使用的参数。
histfit
fitdist
pd = fitdist(r,'Normal')
pd = NormalDistribution Normal distribution mu = 10.1231 [9.89244, 10.3537] sigma = 1.1624 [1.02059, 1.35033]
参数估计值旁边的区间是分布参数的 95% 置信区间。
使用六个 bin 构造具有正态分布拟合的直方图。
histfit(r,6)
使用参数 (3,10) 从 beta 分布生成大小为 100 的样本。
rng default; % For reproducibility b = betarnd(3,10,100,1);
使用 10 个 bin 构造具有 beta 分布拟合的直方图。
histfit(b,10,'beta')
rng default; % For reproducibility b = betarnd(3,10,[100,1]);
使用 10 个 bin 构造具有平滑函数拟合的直方图。
histfit(b,10,'kernel')
用均值 3 和方差 1 从正态分布生成大小为 100 的样本。
3
1
100
rng('default') % For reproducibility r = normrnd(3,1,100,1);
创建一个包含两个子图的图窗,并以 ax1 和 ax2 形式返回 Axes 对象。通过引用对应的 Axes 对象,在每个坐标区中创建一个具有正态分布拟合的直方图。在左侧子图中,绘制一个具有 10 个 bin 的直方图。在右侧子图中,绘制一个具有 5 个 bin 的直方图。通过将对应的 Axes 对象传递给 title 函数,为每个绘图添加标题。
ax1
ax2
title
ax1 = subplot(1,2,1); % Left subplot histfit(ax1,r,10,'normal') title(ax1,'Left Subplot') ax2 = subplot(1,2,2); % Right subplot histfit(ax2,r,5,'normal') title(ax2,'Right Subplot')
rng default % for reproducibility r = normrnd(10,1,100,1);
h = histfit(r,10,'normal')
h = 2×1 graphics array: Bar Line
更改直方图的条形颜色。
h(1).FaceColor = [.8 .8 1];
更改密度曲线的颜色。
h(2).Color = [.2 .2 .2];
输入数据,指定为向量。
示例: data = [1.5 2.5 4.6 1.2 3.4]
data = [1.5 2.5 4.6 1.2 3.4]
示例: data = [1.5 2.5 4.6 1.2 3.4]'
data = [1.5 2.5 4.6 1.2 3.4]'
数据类型: double | single
double
single
直方图的 bin 个数,指定为正整数。默认值为 data 中元素数的平方根,向上舍入。在拟合分布时,使用 [ ] 表示使用默认的 bin 个数。
示例: y = histfit(x,8)
y = histfit(x,8)
示例: y = histfit(x,10,'gamma')
y = histfit(x,10,'gamma')
示例: y = histfit(x,[ ],'weibull')
y = histfit(x,[ ],'weibull')
'normal'
要与直方图拟合的分布,指定为字符向量或字符串标量。下表显示支持的分布。
'Beta'
BetaDistribution
'BirnbaumSaunders'
BirnbaumSaundersDistribution
'Burr'
BurrDistribution
'Exponential'
ExponentialDistribution
'Extreme Value'
'ev'
ExtremeValueDistribution
'Gamma'
GammaDistribution
'Generalized Extreme Value'
'gev'
GeneralizedExtremeValueDistribution
'Generalized Pareto'
'gp'
GeneralizedParetoDistribution
'Half Normal'
'hn'
HalfNormalDistribution
'InverseGaussian'
InverseGaussianDistribution
'Kernel'
KernelDistribution
'Logistic'
LogisticDistribution
'Loglogistic'
LoglogisticDistribution
'Lognormal'
LognormalDistribution
'Nakagami'
NakagamiDistribution
'Negative Binomial'
'nbin'
NegativeBinomialDistribution
'Normal'
NormalDistribution
'Poisson'
PoissonDistribution
'Rayleigh'
RayleighDistribution
'Rician'
RicianDistribution
'Stable'
StableDistribution
'tLocationScale'
tLocationScaleDistribution
'Weibull'
'wbl'
WeibullDistribution
绘图的坐标区,指定为 Axes 对象。如果未指定 ax,则 histfit 使用当前坐标区创建绘图。有关创建 Axes 对象的详细信息,请参阅 axes。
axes
以向量形式返回的绘图句柄,其中 h(1) 是直方图句柄,h(2) 是密度曲线句柄。histfit 对密度进行归一化,使曲线下的总面积与直方图的总面积相匹配。
全部展开
用法说明和限制:
不能将输入参量 dist 指定为 'Rician' 或 'Stable'。
有关详细信息,请参阅在 GPU 上运行 MATLAB 函数 (Parallel Computing Toolbox)。
在 R2006a 之前推出
histogram | normfit | fitdist | paramci
histogram
normfit
paramci
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处