Number of counts in matrix
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How to count the number of individual elements in a matrix using matlab? I mean the number of times individual elements appear.
0 Kommentare
Akzeptierte Antwort
Voss
am 3 Apr. 2024
Example:
A = [1 1 2; 2 1 2; 3 1 1]
nnz(A == 1) % number of times 1 appears in A
nnz(A == 2) % number of times 2 appears in A
nnz(A == 3) % number of times 3 appears in A
4 Kommentare
Weitere Antworten (1)
Steven Lord
am 3 Apr. 2024
Use histcounts with unique (or uniquetol) to generate the bins. You will need to add one more bin at the end since the last bin includes both its edges (unlike the other bins, which only include their left edges.) I would use inf as the right-most end of that last bin.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!