MATLAB中histogram函数的使用 |
您所在的位置:网站首页 › 函数的叠加论文怎么写 › MATLAB中histogram函数的使用 |
目录 语法 说明 示例 向量直方图 指定直方图的 bin 数量 更改直方图的 bin 数量 指定直方图的 bin 边界 绘制分类直方图 具有指定归一化的直方图 绘制多个直方图 调整直方图属性 确定基本概率分布 保存并加载直方图对象 histogram函数的作用是绘制直方图 直方图属于数值数据的条形图类型,将数据分组为 bin。创建 Histogram 对象后,可以通过更改直方图的属性值修改它的各个方面。这对快速修改 bin 属性或更改显示特别有用。 语法 histogram(X) histogram(X,nbins) histogram(X,edges) histogram('BinEdges',edges,'BinCounts',counts) histogram(C) histogram(C,Categories) histogram('Categories',Categories,'BinCounts',counts) histogram(___,Name,Value) histogram(ax,___) h = histogram(___) 说明histogram(X) 基于 X 创建直方图。histogram 函数使用自动分 bin 算法,然后返回均匀宽度的 bin,这些 bin 可涵盖 X 中的元素范围并显示分布的基本形状。histogram 将 bin 显示为矩形,这样每个矩形的高度就表示 bin 中的元素数量。 histogram(X,nbins) 使用标量 nbins 指定的 bin 数量。 histogram(X,edges) 将 X 划分为由向量 edges 来指定 bin 边界的 bin。每个 bin 都包含左边界,但不包含右边界,除了同时包含两个边界的最后一个 bin 外。 histogram('BinEdges',edges,'BinCounts',counts) 手动指定 bin 边界和关联的 bin 计数。histogram 绘制指定的 bin 计数,而不执行任何数据分 bin。 histogram(C)(其中 C 为分类数组)通过为 C 中的每个类别绘制一个条形来绘制直方图。 histogram(C,Categories) 仅绘制 Categories 指定的类别的子集。 histogram('Categories',Categories,'BinCounts',counts) 手动指定类别和关联的 bin 计数。histogram 绘制指定的 bin 计数,而不执行任何数据分 bin。 histogram(___,Name,Value) 使用前面的任何语法指定具有一个或多个 Name,Value 对组参数的其他选项。例如,可以指定 'BinWidth' 和一个标量以调整 bin 的宽度,或指定 'Normalization' 和一个有效选项('count'、'probability'、'countdensity'、'pdf'、'cumcount' 或 'cdf')以使用不同类型的归一化。 histogram(ax,___) 将图形绘制到 ax 指定的坐标区中,而不是当前坐标区 (gca) 中。选项 ax 可以位于前面的语法中的任何输入参数组合之前。 h = histogram(___) 返回 Histogram 对象。使用此语法可检查并调整直方图的属性。 示例 向量直方图生成 10,000 个随机数并创建直方图。histogram 函数自动选择合适的 bin 数量,以便涵盖 x 中的值范围并显示基本分布的形状。 x = randn(10000,1); h = histogram(x) h = Histogram with properties: Data: [10000x1 double] Values: [2 2 1 6 7 17 29 57 86 133 193 271 331 421 540 613 ... ] NumBins: 37 BinEdges: [-3.8000 -3.6000 -3.4000 -3.2000 -3 -2.8000 -2.6000 ... ] BinWidth: 0.2000 BinLimits: [-3.8000 3.6000] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties指定 histogram 函数的输出参数时,它返回一个二元直方图对象。可以使用该对象检查直方图的属性,例如 bin 数量或宽度。 计算直方图的 bin 数量。 nbins = h.NumBins nbins = 37 指定直方图的 bin 数量对分类为 25 个等距 bin 的 1,000 个随机数绘制直方图。 x = randn(1000,1); nbins = 25; h = histogram(x,nbins) h = Histogram with properties: Data: [1000x1 double] Values: [1 3 0 6 14 19 31 54 74 80 92 122 104 115 88 80 38 32 ... ] NumBins: 25 BinEdges: [-3.4000 -3.1200 -2.8400 -2.5600 -2.2800 -2 -1.7200 ... ] BinWidth: 0.2800 BinLimits: [-3.4000 3.6000] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties求 bin 计数。 counts = h.Values counts = 1×25 1 3 0 6 14 19 31 54 74 80 92 122 104 115 88 80 38 32 21 9 5 5 5 0 2 更改直方图的 bin 数量生成 1,000 个随机数并创建直方图。 X = randn(1000,1); h = histogram(X) h = Histogram with properties: Data: [1000x1 double] Values: [3 1 2 15 17 27 53 79 85 101 127 110 124 95 67 32 27 ... ] NumBins: 23 BinEdges: [-3.3000 -3.0000 -2.7000 -2.4000 -2.1000 -1.8000 ... ] BinWidth: 0.3000 BinLimits: [-3.3000 3.6000] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties使用 morebins 函数粗略调整 bin 数量。 Nbins = morebins(h); Nbins = morebins(h) Nbins = 29通过显式设置 bin 数按精细颗粒级别调整 bin。 h.NumBins = 31; 指定直方图的 bin 边界生成 1,000 个随机数并创建直方图。将 bin 边界指定为向量,使宽 bin 在直方图的两边,以捕获不满足 ∣x∣ |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |