Counting certain values from an array

2 次查看(过去 30 天)
Suppose we have an array r=(2,2,2) filled with zeros and ones. How to count up how many zeros and how many ones do we have?

采纳的回答

Image Analyst
Image Analyst 2016-9-22
Try this:
numOnes = sum(r(:))
numZeros = numel(r) - numOnes
  4 个评论
Vadim Tambovtsev
Vadim Tambovtsev 2016-9-22
编辑:Image Analyst 2016-9-22
quality control:
dd=[ 3 7; 4 5]
num7=sum(find(dd==7))
output:
num7= 3
Why is it 3? isn't it supposed to be 1, because there is 1 "7" in the array?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by