Total number of zeros , ones , twos..etc in a matrix

7 Ansichten (letzte 30 Tage)
Joydeb Saha
Joydeb Saha am 9 Dez. 2020
Kommentiert: Joydeb Saha am 9 Dez. 2020
I have a matrix where in the fourth column there will be numbers of 0 to 23. I need a separate matrix where there will be the total numbers of 0s, 1s,2s ..23s etc. Say there will be 1000 0s, 3000 1s 24000 11s etc.
  2 Kommentare
Elimelech Schreiber
Elimelech Schreiber am 9 Dez. 2020
histcounts()
specifically for your problem:
histcounts(x(:,4), (-1:max(x(:,4)))+0.5)
Walter Roberson
Walter Roberson am 9 Dez. 2020
Bearbeitet: Walter Roberson am 9 Dez. 2020
accumarray() together with findgroups(). Or use groupcounts()
I will not post code as I have a suspicion this is homework.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KSSV
KSSV am 9 Dez. 2020
Let a be your data array.
[count_unique, unique_a] = hist(a,unique(a)) ;

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by