How to extract the data points from histogram
75 次查看(过去 30 天)
显示 更早的评论
Hello, I have histogram figure (attached below). Now I need the bin and y axis values. How can I do that?
Thanks.
0 个评论
采纳的回答
Image Analyst
2019-11-21
Try this:
data = randn(1, 5000);
histObject = histogram(data)
grid on;
% Get the bin values into their own separate variable.
counts = histObject.Values
% Get the Y axis limits:
yl = ylim()
% Get the y Axis tick marks
yt = yticks
Don't use a semicolon. In the command window, you'll see the properties of the histogram including the BinEdges, Data, Counts, etc.
histObject =
Histogram with properties:
Data: [1×5000 double]
Values: [1 0 4 3 9 21 26 45 60 107 125 162 238 271 324 340 383 365 404 379 351 315 278 223 189 119 79 75 40 22 15 10 4 8 2 2 0 0 1]
NumBins: 39
BinEdges: [1×40 double]
BinWidth: 0.2
BinLimits: [-3.6 4.2]
Normalization: 'count'
FaceColor: 'auto'
EdgeColor: [0 0 0]
Show all properties
counts =
Columns 1 through 27
1 0 4 3 9 21 26 45 60 107 125 162 238 271 324 340 383 365 404 379 351 315 278 223 189 119 79
Columns 28 through 39
75 40 22 15 10 4 8 2 2 0 0 1
yl =
0 450
yt =
0 50 100 150 200 250 300 350 400 450
2 个评论
Majed Alharthi
2021-4-12
it tells me that: The variable h_pdf.Values does not exist.
can anyone help me?
Image Analyst
2021-4-12
@Majed Alharthi, I think maybe you replied to the wrong post. My code has no such variable (h_pdf) and when I copy my code above and run it again, no such error gets thrown. Start a new question and attach your code that threw the error.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!