Histogram or bar graph with greater than bin?

21 Ansichten (letzte 30 Tage)
Sean Dobson
Sean Dobson am 4 Aug. 2022
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]

Akzeptierte Antwort

Bjorn Gustavsson
Bjorn Gustavsson am 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 Kommentare
Sean Dobson
Sean Dobson am 5 Aug. 2022
Thank you for your help!
Bjorn Gustavsson
Bjorn Gustavsson am 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'})

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Kevin Holly
Kevin Holly am 5 Aug. 2022
Bearbeitet: Kevin Holly am 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

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by