Division using for loop

11 ビュー (過去 30 日間)
Drew Eager
Drew Eager 2021 年 8 月 17 日
コメント済み: darova 2021 年 8 月 19 日
Hi All,
I need to use for loop to divide elements of two arrays. I know it's more effcient to use vectors but the task specifies for loop.
eg.
A= [1 2 3 4 5]
B = [2 3 4 5 6]
How do I divide each element by the corresponfin element in A & B using for loop?
Thanks

回答 (1 件)

Awais Saeed
Awais Saeed 2021 年 8 月 17 日
A= [1 2 3 4 5]
B = [2 3 4 5 6]
for col = 1:1:size(A,2)
result(col) = A(col)/B(col); % equal to A./B right division
end
  2 件のコメント
Drew Eager
Drew Eager 2021 年 8 月 17 日
That works, very helpful. Thank you.
darova
darova 2021 年 8 月 19 日
too easy for me

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

カテゴリ

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