histc vs. histcouns

2 ビュー (過去 30 日間)
Gunther Schaaf
Gunther Schaaf 2022 年 1 月 12 日
回答済み: Bruno Luong 2022 年 1 月 12 日
Matlab recommends to replace histc by histcounts. However, I obtain different results:
x=[123.1900 120.9395 120.9395 120.9395 112.6711 415.4625];
y=[112.6711 120.9395 123.1900 415.4625]
which yields
K>> histc(xRd(:),auxVecX)
ans =
1
3
1
1
but
histcounts(xRd(:),auxVecX)
ans =
1 3 2
How can I handle histcounts so that the outputs are the same?
  1 件のコメント
Gunther Schaaf
Gunther Schaaf 2022 年 1 月 12 日
Sorry, I meant histc(x,y) versus histcounts(x,y).

サインインしてコメントする。

採用された回答

Bruno Luong
Bruno Luong 2022 年 1 月 12 日
The result differ by the way the last bin is handed in both function. To get the same result you must change the last edge to Inf for histc
x=[123.1900 120.9395 120.9395 120.9395 112.6711 415.4625];
y=[112.6711 120.9395 123.1900 415.4625];
xRd = x;
auxVecX = y;
auxVecX(end) = Inf
auxVecX = 1×4
112.6711 120.9395 123.1900 Inf
histc(xRd(:),auxVecX)
ans = 4×1
1 3 2 0

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by