histc vs. histcouns

19 vues (au cours des 30 derniers jours)
Gunther Schaaf
Gunther Schaaf le 12 Jan 2022
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 commentaire
Gunther Schaaf
Gunther Schaaf le 12 Jan 2022
Sorry, I meant histc(x,y) versus histcounts(x,y).

Connectez-vous pour commenter.

Réponse acceptée

Bruno Luong
Bruno Luong le 12 Jan 2022
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

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by