histc vs. histcouns

2 visualizzazioni (ultimi 30 giorni)
Gunther Schaaf
Gunther Schaaf il 12 Gen 2022
Risposto: Bruno Luong il 12 Gen 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 Commento
Gunther Schaaf
Gunther Schaaf il 12 Gen 2022
Sorry, I meant histc(x,y) versus histcounts(x,y).

Accedi per commentare.

Risposta accettata

Bruno Luong
Bruno Luong il 12 Gen 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

Più risposte (0)

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by