Division using for loop

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

Respuestas (1)

Awais Saeed
Awais Saeed el 17 de Ag. de 2021

1 voto

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 comentarios

Drew Eager
Drew Eager el 17 de Ag. de 2021
That works, very helpful. Thank you.
darova
darova el 19 de Ag. de 2021
too easy for me

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 17 de Ag. de 2021

Comentada:

el 19 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by