Matlab中直方图的绘制histogram函数

Matlab中直方图的绘制

histogram函数

直方图属于数值数据的条形图类型,将数据分组为 bin。创建 Histogram 对象后,可以通过更改直方图的属性值修改它的各个方面。

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(___)

注释:
X-要分布到各bin的数据
C-分类数据
nbins-bin数量
edges-bin边界
Categories-直方图中包含的类别
counts-bin计数
ax-目标坐标区

1.向量直方图

生成 10,000 个随机数并创建直方图。histogram 函数自动选择合适的 bin 数量,以便涵盖 x 中的值范围并显示基本分布的形状。

x = randn(10000,1);
h = histogram(x)

在这里插入图片描述
2.指定直方图的bin数量

对分类为 25 个等距 bin 的 1,000 个随机数绘制直方图。

x = randn(1000,1);
nbins = 25;
h = histogram(x,nbins)

在这里插入图片描述
3.更改直方图的bin数量

生成 1,000 个随机数并创建直方图。

X = randn(1000,1);
h = histogram(X)

在这里插入图片描述
使用 morebins 函数粗略调整 bin 数量。

Nbins = morebins(h);
Nbins = morebins(h)

在这里插入图片描述
4.指定直方图bin的边界

生成 1,000 个随机数并创建直方图。将 bin 边界指定为向量,使宽 bin 在直方图的两边,以捕获不满足 的离群值。第一个向量元素是第一个 bin 的左边界,而最后一个向量元素是最后一个 bin 的右边界。

x = randn(1000,1);
edges = [-10 -2:0.25:2 10];
h = histogram(x,edges);

在这里插入图片描述
将 Normalization 属性指定为 ‘countdensity’ 以使包含离群值的 bin 扁平化。现在,每个 bin 的区域(而不是高度)表示该 bin 的观测值频率。

h.Normalization = 'countdensity';

在这里插入图片描述
5.绘制分类直方图
创建一个表示投票的分类向量。该向量中的类别是 ‘yes’、‘no’ 或 ‘undecided’。

A = [0 0 1 1 1 0 0 0 0 NaN NaN 1 0 0 0 1 0 1 0 1 0 0 0 1 1 1 1];
C = categorical(A,[1 0 NaN],{'yes','no','undecided'})
h = histogram(C,'BarWidth',0.5)

在这里插入图片描述
6.具有指定归一化的直方图
生成 1,000 个随机数并使用 ‘probability’ 归一化创建直方图。

x = randn(1000,1);
h = histogram(x,'Normalization','probability')

在这里插入图片描述

7.调整直方图属性
准确指定bin数量

x = randn(1000,1);
h = histogram(x)
h.NumBins = 15;

在这里插入图片描述
通过向量指定 bin 边界。向量中的第一个值是第一个 bin 的左边界。最后一个值是最后一个 bin 的右边界。

x = randn(1000,1);
h = histogram(x)
h.BinEdges = [-3:3];

在这里插入图片描述
8.确定基本概率分布

x = 2*randn(5000,1) + 5;
histogram(x,'Normalization','pdf')

在这里插入图片描述
对于均值为 5、标准差为 2 的正态分布,叠加一个概率密度函数图。

x = 2*randn(5000,1) + 5;
histogram(x,'Normalization','pdf')
hold on
y = -5:0.1:15;
mu = 5;
sigma = 2;
f = exp(-(y-mu).^2./(2*sigma^2))./(sigma*sqrt(2*pi));
plot(y,f,'LineWidth',1.5)

在这里插入图片描述
9.Matlab中更改直方图颜色

x = randn(1000,1);
h = histogram(x)
h.BinEdges = [-3:3];
h.FaceColor = [0 0.8 0.5];
h.EdgeColor = 'm';

在这里插入图片描述
10.Matlab中绘制多个直方图histogram函数
生成两个随机数向量并在同一图窗中针对每个向量绘制对应的一个直方图。

x = randn(2000,1);
y = 1 + randn(5000,1);
h1 = histogram(x);
hold on
h2 = histogram(y);

在这里插入图片描述
由于直方图的示例大小和 bin 宽度不同,很难将它们进行比较。对这些直方图进行归一化,这样所有的条形高度相加的结果为 1 并使用统一的 bin 宽度。

h1.Normalization = 'probability';
h1.BinWidth = 0.25;
h2.Normalization = 'probability';
h2.BinWidth = 0.25;

在这里插入图片描述

基于Matlab直方图Histogram的人脸识别程序-Processed histogram based Face Recognition.part1.rar 基于Matlab 直方图Histogram的人脸识别程序 因为数据库图片太大,所以分成几个压缩文件。 Face recognition 原理介绍: matlab12.jpg Recognizing objects from large image databases, histogram based methods have proved simplicity and usefulness in last decade. Initially, this idea was based on color histograms that were launched by swain [1]. This algorithm presents the first part of our proposed technique named as “Histogram processed Face Recognition” [2] For training, grayscale images with 256 gray levels are used. Firstly, frequency of every gray-level is computed and stored in vectors for further processing. Secondly, mean of consecutive nine frequencies from the stored vectors is calculated and are stored in another vectors for later use in testing phase. This mean vector is used for calculating the absolute differences among the mean of trained images and the test image. Finally the minimum difference found identifies the matched class with test image. Recognition accuracy is of 99.75% [1] M. J. Swain and D. H. Ballard, “Indexing via color histogram”, In Proceedings of third international conference on Computer Vision , pages 390–393, Osaka, Japan, 1990. [2] Fazl-e-Basit, Younus Javed and Usman Qayyum, "Face Recognition using processed histogram and phase only correlation ", 3rd IEEE International Conference on Emerging Technology pp. 238-242
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只佳佳怪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值