Histogram shows one value at the very end that ruins the plot
2 views (last 30 days)
Show older comments
Hello I have a vactor of values and I am ploting a histogram. I get one value at the very end that is ruining my plot. I cannot get rid of this. Can you please help.
My code is simple and is below. I have also attached data file RT160 in .mat format. Please help.
figure(1);
histogram(RT160,150);
xlabel('Cost (USD)');
ylabel('Counts');
1 Comment
Answers (1)
Steven Lord
on 9 Mar 2022
If that last bin is (roughly) twice as high as you think it should be, that's because the last bin includes both values that match its left bin edge and values that match its right bin edge. The rest of the bins include just their left bin edge (leaving their right bin edge to their neighbor to the right.)
x = randi(10, 1, 1e3);
figure
histogram(x, 1:10) % Last bin contains both 9 and 10
figure
histogram(x, 1:11) % Last bin is [10, 11] which matches only 10 in x
I'd just add one element at the end of my bin edges, the max of my data plus my desired BinWidth.
desiredBinWidth = 1;
newUpperLimit = max(x) + desiredBinWidth
0 Comments
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!