フィルターのクリア

Average of adding two single numbers in two different column vectors

4 ビュー (過去 30 日間)
BenSven
BenSven 2024 年 1 月 22 日
回答済み: Shubham 2024 年 1 月 23 日
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 件)

Shubham
Shubham 2024 年 1 月 23 日
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.

カテゴリ

Help Center および File ExchangeNaNs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by