Centering histogram bins and setting percentage range in Matlab

孤者浪人 提交于 2019-12-29 09:19:42

问题


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.

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:


回答1:


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('%')


来源:https://stackoverflow.com/questions/19448650/centering-histogram-bins-and-setting-percentage-range-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!