Number of counts in matrix
2 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Voss
2024-4-3
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
更多回答(1 个)
Steven Lord
2024-4-3
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!