Sum of certain value in a matrix
Show older comments
I have a 241 x 340 matrix that contains only 1 and 0 value scattered over the matrix. My question is how can I calculate the sum value of 1 in the matrix? Thank You in advance. for example
A = [0 0 0 0 1 1 1 1 0 0 1 1 1 0; 1 1 1 0 0 1 1 1 0 0 0 1 1 0]
Accepted Answer
More Answers (2)
A = [0 0 0 0 1 1 1 1 0 0 1 1 1 0; 1 1 1 0 0 1 1 1 0 0 0 1 1 0]
edges = unique(A)
counts = histc(A(:), edges)
Aniruddha Katre
on 3 May 2017
0 votes
Categories
Find more on Sparse Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!