Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
820 views
in Technique[技术] by (71.8m points)

plot - Centering histogram bins and setting percentage range in Matlab

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:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...