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

1 回表示 (過去 30 日間)
Alana Duffy
Alana Duffy 2017 年 10 月 2 日
編集済み: Jan 2017 年 10 月 2 日
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 件のコメント
Jan
Jan 2017 年 10 月 2 日
編集済み: Jan 2017 年 10 月 2 日
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.

サインインしてコメントする。

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2017 年 10 月 2 日
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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by