How to get values over x-axis from a plotted Histogram?
29 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
Srivardhan Gadila
2020-5-1
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!