Effacer les filtres
Effacer les filtres

Histogram shows one value at the very end that ruins the plot

2 vues (au cours des 30 derniers jours)
Sanchit Sharma
Sanchit Sharma le 9 Mar 2022
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 commentaire
HWIK
HWIK le 9 Mar 2022
If what you want is just to omit that value you can just change the x limits

Connectez-vous pour commenter.

Réponses (1)

Steven Lord
Steven Lord le 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
newUpperLimit = 11

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by