How to show the bin' percentage values' in a histogram?
10 views (last 30 days)
Show older comments
Mukul Rao, I am really new in MATLAB and I would appreciate if direct me about this rodimentary question. I want to show the bin counts "percentage values" in histogram and my code is below but something is wrong and I can not find it!! Thank you n advance!
binranges = -0.06:0.08;
[bincounts] = histc(x,binranges);
percentagevalues = bincounts./sum(bincounts) * 100;
for i = 1:length(bincounts)-1
x = (binranges(i) + binranges(i+1))/2;
y = bincounts(i)+1;
Cris LaPierre on 4 Mar 2021
The issue is with how you defined your binranges. When you don't specify a step size, the colon operator uses 1.
binranges = -0.06:0.08
Since bin edges must contain at least 2 values, the result of histc is bincounts=0. Run your code with your desired stepsize and it will work.
binranges = -0.06:0.01:0.08
More Answers (1)
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!