Division using for loop
9 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Awais Saeed
on 17 Aug 2021
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
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!