필터 지우기
필터 지우기

How can I retrieve data from an histogram?

조회 수: 50 (최근 30일)
Matteo
Matteo 2015년 3월 2일
댓글: Gonzalo Agudelo 2019년 4월 28일
Hi Everyone,
I have created a figure using histfit(NUMERIC1,n,'normal') where 'NUMERIC1' is the vector, 'n' the number of histograms i want to plot and 'normal' refers to the normal distribution
Once the figure is plotted I get the normal distribution of the vector 'NUMERIC1'. Now, I want to retrieve the data (so the value of the vector 'NUMERIC1') that are contained in each bar. How can I do that?
Thanks,
Matteo

채택된 답변

Adam
Adam 2015년 3월 2일
hHist = histfit( rand(100,1), 3, 'normal' )
hHist(1).YData
will give you the numbers if you extract the values from what that gives you.
hHist should be a vector of two graphics handles, the first is a patch that renders the bar chart (the 2nd is a Line object).
Because it is a patch object you get the YData out in slightly less obvious format than you would for a line plot, but the values you want are obvious from its result.
  댓글 수: 9
Star Strider
Star Strider 2015년 3월 2일
@Matteo — If Adam’s Answer solved your problem, please Accept it.
Matteo
Matteo 2015년 3월 2일
Done!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chuck
Chuck 2017년 9월 26일
In newer versions of MATLAB, all you need to do is:
counts = h.Values
This will give you the number of values in each bin. You can change the name after the dot above to any of the following:
'BinCounts', 'BinCountsMode', 'BinEdges', 'BinLimits', 'BinLimitsMode', 'BinMethod', 'BinWidth', 'BusyAction', 'ButtonDownFcn', 'CreateFcn', 'Data', 'DeleteFcn', 'DisplayName', 'DisplayStyle', 'EdgeAlpha', 'EdgeColor', 'FaceAlpha', 'FaceColor', 'HandleVisibility', 'HitTest', 'Interruptible', 'LineStyle', 'LineWidth', 'Normalization', 'NumBins', 'Orientation', 'Parent', 'PickableParts', 'Selected', 'SelectionHighlight', 'Tag', 'UIContextMenu', 'UserData', 'Visible', 'Categories'
For example, to call the bin limits:
h.BinLimits
  댓글 수: 1
Gonzalo Agudelo
Gonzalo Agudelo 2019년 4월 28일
You were able to aquire the number of values per bin, but could you get the values themselves?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by