How to average each row from two indivisual comlum vectors?

Assume two column vectors with same number of rows:
1 4
2 3
3 2
4 1
I would like to average each row and store this in a new variable hence will be:
2.5
2.5
2.5
2.5

답변 (1개)

Bob Thompson
Bob Thompson 2021년 3월 1일
The mean command has an option to average in a specific dimension.
A = [1 4;
2 3;
3 2;
4 1];
B = mean(A,2);

댓글 수: 2

Thanks, however this seems abit cumbersome as I have 40 rows.Additionally, the vectors are two are seperate vectors, they are not 1 as you have dsiplayed as A in your answer.
If you have 40 rows, aren't you going to end up with 40 results no matter what? Do you not want the average for all individual rows?
As for the two separate vectors, just combine them.
A = [1; 2; 3; 4];
B = [4; 3; 2; 1];
C = [A, B];
D = mean(C,2);

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2021년 3월 1일

댓글:

2021년 3월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by