Histogram or bar graph with greater than bin?

조회 수: 21 (최근 30일)
Sean Dobson
Sean Dobson 2022년 8월 4일
댓글: Bjorn Gustavsson 2022년 8월 5일
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]

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2022년 8월 5일
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
Sean Dobson
Sean Dobson 2022년 8월 5일
Thank you for your help!
Bjorn Gustavsson
Bjorn Gustavsson 2022년 8월 5일
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'})

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Kevin Holly
Kevin Holly 2022년 8월 5일
편집: Kevin Holly 2022년 8월 5일
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

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by