Average of adding two single numbers in two different column vectors
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have two row vectors .
e.g
3 4 5 6 7
1 2 4 6 7
I need to add the two sevens and find the average of the sum (14)
How do I do that please?
Thanks
1 comentario
Respuestas (1)
Shubham
el 23 de En. de 2024
Hi Richard,
To add the last elements of two row vectors and find the average of their sum MATLAB, you can simply access the last elements of each vector by using end keyword and add them together then divide by 2 to get the average.
Here's how you can do it:
% Define the row vectors
vector1 = [3 4 5 6 7];
vector2 = [1 2 4 6 7];
% Add the last elements of both vectors
sum_of_last_elements = vector1(end) + vector2(end);
% Calculate the average of the sum
average_of_sum = sum_of_last_elements / 2;
% Display the result
disp(average_of_sum);
When you run this code, it will display the average of the last elements (which are both 7 in your example), so the output will be 7 since the sum is 14 and the average is 14/2 = 7.
0 comentarios
Ver también
Categorías
Más información sobre NaNs en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!