histc vs. histcouns

2 Ansichten (letzte 30 Tage)
Gunther Schaaf
Gunther Schaaf am 12 Jan. 2022
Beantwortet: Bruno Luong am 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 Kommentar
Gunther Schaaf
Gunther Schaaf am 12 Jan. 2022
Sorry, I meant histc(x,y) versus histcounts(x,y).

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 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

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by