How to get values over x-axis from a plotted Histogram?
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Abhimanyu Gupta
le 25 Avr 2020
Réponse apportée : Srivardhan Gadila
le 1 Mai 2020
I plotted a histogram using the historgram() method, somewhat similar to this-

I wish to note the values over y-axis and x-axis.
I can get the values over y-axis pretty easily using histogram.Values.
For corresponding x-axis values, using the histogram.BinEdges, I get values as: -0.5 0.5 1.5 2.5 3.5 4.5 5.5, but what I want is: 0 1 2 3 4 5.
I tried looking into complete properties of Histogram but coudln't found a property useful to me.
I could do that manually by running the following piece of code.
ranges=Histogram.BinEdges;
x=zeros(Histogram.NumBins,1);
for i=1:Histogram.NumBins
x(i)=(ranges(i)+ranges(i+1))/2;
end
But I believe there should be some inbuilt method/property to do this.
So, is there some property/method which I can use to get the desired values?
1 commentaire
Réponse acceptée
Srivardhan Gadila
le 1 Mai 2020
Seems that from the documentation of histogram & Histogram Properties there isn't any built in property to get the values you are looking for.
binEdges = Histogram.BinEdges;
x = binEdges(1:end-1) + Histogram.BinWidth/2;
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Histograms 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!