count even numbers of a matrix

13 visualizzazioni (ultimi 30 giorni)
Zisan Rahman
Zisan Rahman il 28 Dic 2021
Commentato: Rik il 29 Dic 2021
Found how many even numbers are present in a 3×3 matrix. And find the value of multiple of those even numbers.
  1 Commento
Rik
Rik il 29 Dic 2021
Why did you remove your comment ("n=3; A=magic(n) for i=1:n*n for p=A(i) if rem(p,2)==0 p; end end end i tried this. but could not find the proper answer")?

Accedi per commentare.

Risposte (2)

Rik
Rik il 28 Dic 2021
This sounds a lot like homework. What did you try? I think you will be able to do it yourself if you read the documentation for the mod function.

Image Analyst
Image Analyst il 28 Dic 2021
No double for loop needed. Try this:
n=3;
A=magic(n)
remainders = rem(A, 2) == 0
then use sum() to count the 1's.

Categorie

Scopri di più su MATLAB 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