Sum of certain value in a matrix

1 次查看(过去 30 天)
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]

采纳的回答

Andrei Bobrov
Andrei Bobrov 2017-5-3
out = sum(A(:))

更多回答(2 个)

KL
KL 2017-5-3
编辑:KL 2017-5-3
See Image Analyst's answer here
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
Aniruddha Katre 2017-5-3

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by