简体   繁体   English

如何在Matlab的“直方图”功能中标准化Y轴

[英]How to normalize Y axis in “histogram” function in matlab

I am using histogram command to plot 3 histogram in one figure and I have completed function with histogram command and I dont want to rewrite it for old hist command. 我正在使用直方图命令在一个图中绘制3个直方图,并且已经完成了直方图命令的功能,并且我不想为旧的hist命令重写它。 However Im unable to normalize Y axis, because h.Values vector is read only. 但是,Im无法归一化Y轴,因为h.Values向量是只读的。

h=histogram(data,'Normalization','pdf');
h.Values=(h.Values-min(h.Values))/(max(h.Values)-min(h.Values);

Can anybody help me? 有谁能够帮助我? Thanks 谢谢

EDIT after first comment: Yes I read matlab help. 在第一个评论后进行编辑:是的,我阅读了matlab帮助。 In the histogram image example I have PDF on Y axis, but values are from 0 to 3.5. 在直方图图像示例中,我在Y轴上具有PDF,但是值从0到3.5。 I need to normalize from 0 to 1. When I use 'Normalization' parametr with 'probability' I get histogram from 0 to 0.3. 我需要从0到1进行归一化。当我将“归一化”参数与“概率”结合使用时,我会得到从0到0.3的直方图。 I simply need PDF, but from 0 to 1. histogram example 我只需要PDF,但是从0到1。 直方图示例

You may use another 'new' function: 您可以使用另一个“新”功能:

[y, x]=histcounts (x);
x=x(1:end-1)+diff(x/2)

Then you may normalize y as you wish. 然后,您可以根据需要对y进行归一化。 This function also has same normalize arguments as histogram. 此函数还具有与直方图相同的归一化参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM