Counting certain values from an array

10 ビュー (過去 30 日間)
Vadim Tambovtsev
Vadim Tambovtsev 2016 年 9 月 22 日
編集済み: Image Analyst 2016 年 9 月 22 日
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?
Image Analyst
Image Analyst 2016 年 9 月 22 日
Use length() instead of sum().

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical 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