count even numbers of a matrix

13 Ansichten (letzte 30 Tage)
Zisan Rahman
Zisan Rahman am 28 Dez. 2021
Kommentiert: Rik am 29 Dez. 2021
Found how many even numbers are present in a 3×3 matrix. And find the value of multiple of those even numbers.
  1 Kommentar
Rik
Rik am 29 Dez. 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")?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Rik
Rik am 28 Dez. 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 am 28 Dez. 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.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by