在Matlab中居中直方图图元并设置百分比范围 [英] Centering histogram bins and setting percentage range in Matlab
问题描述
我正在Matlab中进行数据分析,并将离散值(1-15)的频率绘制成Matlab上的直方图.我想将垃圾箱居中,以使第一个垃圾箱的中心位于值1上,第二个垃圾箱的中心位于值2上,等等.
I'm doing data-analysis in Matlab and I'm plotting the frequencies of discrete values (1-15) into a histogram on Matlab. I would like to center the bins so that the center of 1st bin is on value 1, center of the 2nd bin is on value 2, etc.
我也想获得Y轴的百分比范围.任何快速的想法如何做到这一点?这是一张突出我的问题的图片:
Also I would like to get percentage range for the Y-axis. Any quick ideas how to do this? Here is a picture highlighting my question:
推荐答案
首先使用 hist
与您的预期中心.然后使用bar
和xlabel
以所需的方式显示带有y轴的直方图:
Start by using hist
with your expected centers. Then use bar
and xlabel
to display the histogram with the y axis the way you want:
dat = randi(15,100,1);
centers = 1:15;
counts = hist(dat,centers);
pcts = 100 * counts / sum(counts);
bar(centers,counts)
ylabel('%')
这篇关于在Matlab中居中直方图图元并设置百分比范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!