How can I combine two columns?

조회 수: 1 (최근 30일)
Andrew
Andrew 2013년 6월 21일
Hi I have a two column matrix. How can I merge and average them?
For example, if the matrix was
5 9
3 1
1 7
Then the output would be
7
2
4

답변 (3개)

Roger Stafford
Roger Stafford 2013년 6월 21일
If M is your two-column matrix
M = mean(M,2);
  댓글 수: 1
Jan
Jan 2013년 6월 21일
Equivalent:
M = sum(X, 2) * 0.5;

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


David Sanchez
David Sanchez 2013년 6월 21일
Use the built-ibn function cat:
a = [1 2; 3 4];
b1 = [2 4];
b2 = [2; 4];
c1 = cat(1,a,b1);
c2 = cat(2,a,b2);
>> c1
c1 =
1 2
3 4
2 4
>> c2
c2 =
1 2 2
3 4 4
read
help cat
for more options.

Chetan Aswathanarayana
Chetan Aswathanarayana 2013년 6월 21일
편집: Chetan Aswathanarayana 2013년 6월 21일
If A = [5 9
3 1
1 7]
>> B = A';
>> B = mean(B);
>> B = B'
B =
7
2
4

카테고리

Help CenterFile Exchange에서 Gamma Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by