Azzera filtri
Azzera filtri

Average of adding two single numbers in two different column vectors

4 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Shubham
Shubham il 23 Gen 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.

Community Treasure Hunt

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

Start Hunting!

Translated by