Counting certain values from an array

11 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Image Analyst
Image Analyst il 22 Set 2016
Try this:
numOnes = sum(r(:))
numZeros = numel(r) - numOnes
  4 Commenti
Vadim Tambovtsev
Vadim Tambovtsev il 22 Set 2016
Modificato: Image Analyst il 22 Set 2016
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 il 22 Set 2016
Use length() instead of sum().

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by