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일

1 개 추천

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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2021년 8월 17일

댓글:

2021년 8월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by