How to show the bin' percentage values' in a histogram?
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!
clc;
clear all;
close all;
%.................................................
data=xlsread('A');
dens=data(:,1);%gr/cm3
x=dens(1:1:end);
hist(x,24);
binranges = -0.06:0.08;
[bincounts] = histc(x,binranges);
percentagevalues = bincounts./sum(bincounts) * 100;
figure(2)
bar(binranges,bincounts,'histc')
for i = 1:length(bincounts)-1
x = (binranges(i) + binranges(i+1))/2;
y = bincounts(i)+1;
text(x,y,num2str(bincounts(i),'%3.2f'),'HorizontalAlignment','center');
end
3 Comments
Cris LaPierre
on 4 Mar 2021
Edited: Cris LaPierre
on 4 Mar 2021
Could you please explain what it is about the result that is wrong?
What version of MATLAB are you using?
Maria Amr
on 4 Mar 2021
Accepted Answer
More Answers (1)
Maria Amr
on 4 Mar 2021
0 votes
Categories
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!