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

1 visualización (últimos 30 días)
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 comentario
Jan
Jan el 2 de Oct. de 2017
Editada: Jan el 2 de Oct. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 2 de Oct. de 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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by