Histogram or bar graph with greater than bin?

21 views (last 30 days)
p=histcounts(a,"BinWidth",10,"BinLimits",[0,250],"Normalization","pdf");
figure
bar(p)
Using 1x252 matrix = a. Several values are greater than 250, the set upper bin limit. How can I bin the values greater than 250, so that they are at the end of the bar graph and assigned to a bin labelled ">250" on the x-axis. I have tried the following code as well:
figure(2);
h=histogram(a,[0:10:250 Inf]);
This will bin those values larger than 250, but it won't normalize them as a pdf. Additionally, the final bar is approximatley twice the width as the others and I cannot assign a greater than symbol. Any guidance would be much appreciated. Thank you.
[SD:edited for further clarity]

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 5 Aug 2022
Maybe something like this would be good enough/a step on the way:
a = 75*randn(2048,1).^2;
h = histogram(min(a,260),0:10:260,'normalization','pdf'),
set(gca,'xtick',[5:50:255],'xticklabel',{'0-10','50-60','100-110','150-160','200-210','>250'})
HTH
  2 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 5 Aug 2022
Your welcome, happy that it helped.
I just realised that it might be possible to spice-up the x-labels one step more:
set(gca,'xtick',[5:50:255],'xticklabel',{'0-10','50-60','100-110','150-160','200-210','250-\infty'})

Sign in to comment.

More Answers (1)

Kevin Holly
Kevin Holly on 5 Aug 2022
Edited: Kevin Holly on 5 Aug 2022
Below is a workaround.
a=260*rand(1,252);
p=histcounts(a,"BinWidth",10,"BinLimits",[0,250],"Normalization","pdf");
figure
bar(p)
figure(2);
h=histogram(a,[0:10:250 Inf]);
figure(3)
b=a;
b(b>250)=251;
h=histogram(b,[0:10:250],"Normalization","pdf",'FaceColor','g');
hold on
h=histogram(b,[250:10:260],"Normalization","pdf");
h.FaceColor = 'r';
set(gca,'xtick',[5:50:255],'xticklabel',{'0-10','50-60','100-110','150-160','200-210','>250'}) %Edit: borrowed from Bjorn

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!