How to get the data as output along with the histogram plot?

조회 수: 5 (최근 30일)
Angana Ray
Angana Ray 2020년 6월 1일
댓글: Angana Ray 2020년 6월 4일
Hi,
I have a set of data which looks like
0.499783
0.499669
0.500231
0.499909
0.499542
0.50018
0.500785
0.49823
.... and so on (say I haev 50000 rows)
Now I am plotting
histogram(S,'Normalization','probability') , where S is the column containing the data.
I get the normalized probability histogram as a plot. But I want the data that is finally plotted, i.e., no. of hits in each bin or something like that. Such that in future I can get the same histogram plot without using the original raw data. Is that possible?

채택된 답변

Tommy
Tommy 2020년 6월 1일
You could request output from histogram():
h = histogram(S,'Normalization','probability');
and access properties such as h.BinEdges, h.BinCounts, h.Values, etc, described here.
Or you could use histcounts(), described here, after you plot your histogram:
histogram(S,'Normalization','probability');
[binCounts,binEdges] = histcounts(S,'Normalization','probability');
  댓글 수: 5
Tommy
Tommy 2020년 6월 3일
A histogram is basically a bunch of adjacent bars, with one bar per bin. So you could determine the centers of each bin and then call bar(), using a width of 1 to avoid any gap between the bins:
binCenters = binEdges(1:end-1) + diff(binEdges)/2;
bar(binCenters, binCounts, 1)
By adjusting the color and x limits (and possibly other properties) you could probably replicate the histogram plot exactly.
Using
histogram('BinEdges', binEdges, 'BinCounts', binCounts)
would definitely create the exact same plot (or at least I assume it would).
Angana Ray
Angana Ray 2020년 6월 4일
Thank you very very much

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

추가 답변 (0개)

카테고리

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