Use loops and/or conditions to make even numbers of a matrix the product of their row and column

1 vue (au cours des 30 derniers jours)
So I have a 6x5 matrix A, created with for loops. It increases across the rows from 1-30 by an increment of 1. I am now supposed to change all even numbers in said matrix to be the product of their row and column, so for example A(2,1) currently = 6 but after the change will equal 2. I cannot use id, only loops or conditions. I don't know what to do other than somehow use implementing rem(A,2) == 0
  1 commentaire
Jan
Jan le 2 Oct 2017
Modifié(e) : Jan le 2 Oct 2017
This sounds like a homework. So please post, what you have tried so far and ask a specific question. It is not useful for you or for the forum, if a complete solution is posted. Note that you could not deliver it as your own work without cheating.
rem(A,2)==0 is a good point to start from. Two loops over the row and column indices will be required also.

Connectez-vous pour commenter.

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 2 Oct 2017
Let A - your array [6 x 5]
B = A;
for ii = 1:size(A,1)
for jj = 1:size(A,2)
t = B(ii,jj)/2;
if t == floor(t)
B(ii,jj) = ii*jj;
end
end
end

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by