How to get values over x-axis from a plotted Histogram?
29 views (last 30 days)
Show older comments
Abhimanyu Gupta
on 25 Apr 2020
Answered: Srivardhan Gadila
on 1 May 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?
Accepted Answer
Srivardhan Gadila
on 1 May 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 Comments
More Answers (0)
See Also
Categories
Find more on Histograms 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!