Histogram or bar graph with greater than bin?

20 visualizaciones (últimos 30 días)
Sean Dobson
Sean Dobson el 4 de Ag. de 2022
Comentada: Bjorn Gustavsson el 5 de Ag. de 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]

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 5 de Ag. de 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 comentarios
Sean Dobson
Sean Dobson el 5 de Ag. de 2022
Thank you for your help!
Bjorn Gustavsson
Bjorn Gustavsson el 5 de Ag. de 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'})

Iniciar sesión para comentar.

Más respuestas (1)

Kevin Holly
Kevin Holly el 5 de Ag. de 2022
Editada: Kevin Holly el 5 de Ag. de 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

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by