How can I calculate average of two values using a for loop
Mostrar comentarios más antiguos
I have to calculate the average of two numbers in different columns but are in the same row. This then has to be repeated for the other 20 rows of numbers I have finding the average between the two numbers.
for ii = 1:20
PTS = {539 1220 996 1485 1938 2019 2461 1557 1819 2832 2430 2323 2201 1970 2078 1616 2133 83 782 1161}
G = {71 79 50 66 68 80 82 65 66 80 77 82 82 73 82 58 78 6 35 66}
ave = PTS./G
end
3 comentarios
Ameer Hamza
el 6 de Abr. de 2020
The variables PTS and G are cell arrays. How do you want to calculate the average between the two?
collegestudent
el 6 de Abr. de 2020
KALYAN ACHARJYA
el 6 de Abr. de 2020
Is the question complete?
Respuesta aceptada
Más respuestas (1)
Ameer Hamza
el 6 de Abr. de 2020
This is a version without a for loop
ave = [PTS{:}]./[G{:}];
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!