Use loops and/or conditions to make even numbers of a matrix the product of their row and column
1 view (last 30 days)
Show older comments
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 Comment
Jan
on 2 Oct 2017
Edited: Jan
on 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.
Answers (1)
Andrei Bobrov
on 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
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!