How do I get identical results from the old hist and the new histcounts

1 回表示 (過去 30 日間)
Jakob Havtorn
Jakob Havtorn 2016 年 7 月 8 日
回答済み: Al in St. Louis 2017 年 11 月 15 日
I am trying to replace a use of the old hist function by the new histcounts which performs faster at binning and counting than hist. However, I am struggling to achieve the exact same results from histcounts that I got from hist.
I am aware that histcounts returns the bin edges rather than the binCenters. However, the counts should be identical and the bin edges should be convertible to bin centers, as far as I understand.
This small piece of code illustrates my problem.
A = randn(100,2);
[N1,binCenters1] = hist(A(:,1),10);
[N2,binEdges2] = histcounts(A(:,1),10);
binCenters2 = mean([binEdges2(1:end-1);binEdges2(2:end)]);
N = [N1;N2;abs(N1-N2)];
binCenters = [binCenters1;binCenters2;abs(binCenters1-binCenters2)];

回答 (1 件)

Al in St. Louis
Al in St. Louis 2017 年 11 月 15 日
I just fall back on hist when I need its functionality.

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by