Use loops and/or conditions to make even numbers of a matrix the product of their row and column
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Jan
am 2 Okt. 2017
Bearbeitet: Jan
am 2 Okt. 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.
Antworten (1)
Andrei Bobrov
am 2 Okt. 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!