Histogram or bar graph with greater than bin?

24 次查看(过去 30 天)
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 个评论
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