How to extract the data points from histogram
73 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kazi Main Uddin Ahmed
le 21 Nov 2019
Commenté : Image Analyst
le 12 Avr 2021
Hello, I have histogram figure (attached below). Now I need the bin and y axis values. How can I do that?
Thanks.
0 commentaires
Réponse acceptée
Image Analyst
le 21 Nov 2019
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 commentaires
Majed Alharthi
le 12 Avr 2021
it tells me that: The variable h_pdf.Values does not exist.
can anyone help me?
Image Analyst
le 12 Avr 2021
@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.
Plus de réponses (1)
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!