Average of adding two single numbers in two different column vectors
2 次查看(过去 30 天)
显示 更早的评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!