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.

采纳的回答

Image Analyst
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
Majed Alharthi 2021-4-12
it tells me that: The variable h_pdf.Values does not exist.
can anyone help me?
Image Analyst
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 个)

Kazi Main Uddin Ahmed
thanks

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by