Populating array with values from each iteration

Hi, I have 2 arrays (arrays A and B) both 9 x 9. I want to compare elements of both. If value of A exceeds corresponding value of B, then the value in new array C will be that of B, otherwise it will be value of A. I tried implementing tHis with for loops but only seem to get the value from last iteration of loop executions. I guess the others are being overwritten after every loop execution. How can I avoid this, or alternatively avoid for loops altogether for quicker computation.
for n=9;
for m=9;
if B(n,m) <= A(n,m)
C(n,m) = B(n,m);
else C(n,m)= A(n,m);
end;
end;
end;

 採用された回答

Yao Li
Yao Li 2013 年 4 月 16 日

0 投票

for n=1:9 and for m=1:9

1 件のコメント

KV
KV 2013 年 4 月 16 日
Ahh school boy error. Many thanks.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

KV
2013 年 4 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by