Histogram: 'Greater than' bin
28 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jessica Hiscocks
le 26 Avr 2018
Réponse apportée : Jessica Hiscocks
le 26 Avr 2018
Simple question but I can't seem to find an answer: How do I add a bin to my histogram for the values outside of the visible range? Plotted automatically, the data below has values ranging from 0-200, the last 5 bins (100-200) have one point each. When I change the bin range to 0-100, those 5 bins are cut off. I want to take the points with values greater than the max(BinEdges) value, and have a bin labelled '>100' (populated dynamically as the bin edges are changed).
h=histogram(grains.area);
h.BinLimits=[0 100];
%Make range labels for bins
label = arrayfun(@(x,y) sprintf('%g - %g',x,y), ...
h.BinEdges(1:end-1), h.BinEdges(2:end), ...
'UniformOutput', false);
%label x axis with bin ranges
set(gca,'XTick',(h.BinEdges(1:end-1)+h.BinEdges(2:end))/2,...
'XTickLabel',label)
% get x position for bin count labels
xLblPos=h.BinEdges(1:end-1)+h.BinWidth/2;
%get y position
lift=max(h.Values)/20;
yLblPos=h.Values+lift;
%label each bar at top
cont=string(h.Values);
text(xLblPos,yLblPos,cont)
0 commentaires
Réponse acceptée
Steven Lord
le 26 Avr 2018
Add -Inf as the first element of the edges vector and/or Inf as the last element.
>> x = randn(1, 1e6);
>> h = histogram(x, [-Inf -2:0.25:2 Inf]);
>> tooSmallH = h.Values(1)
>> tooSmallX = nnz(x < -2)
>> tooLargeH = h.Values(end)
>> tooLargeX = nnz(x > 2)
The two variables whose names start with tooSmall should have the same value, as should the two variables whose names start with tooLarge.
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!