how can I get the mean of each two columns of a matrix ?

조회 수: 18 (최근 30일)
Niki
Niki 2016년 7월 8일
댓글: Star Strider 2016년 7월 8일
I have a big matrix and I want to get the average of each 2 columns,
Is there any function to do that ?

채택된 답변

Star Strider
Star Strider 2016년 7월 8일
I’m not quite sure what you want.
See if this works for you:
M = randi(99, 10);
RM = reshape(M, 10, 2, [])
Mmean = mean(RM,2)
  댓글 수: 2
Niki
Niki 2016년 7월 8일
편집: Niki 2016년 7월 8일
@Star Strider average of each two columns should give me 1 column . means average of each element . Let say if I have 100 columns in my original data, it should give me 50 columns
Star Strider
Star Strider 2016년 7월 8일
I forgot a squeeze call. This will do what you want, and should work with any matrix:
M = randi(99, 10); % Create Data
RM = reshape(M, size(M,1), 2, []) % Reshape
Mmean = squeeze(mean(RM,2)) % Desired Result

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

추가 답변 (1개)

Thorsten
Thorsten 2016년 7월 8일
mean(reshape(mean(X), 2, []))
  댓글 수: 1
Niki
Niki 2016년 7월 8일
편집: Niki 2016년 7월 8일
@Thorsten average of each two columns should give me 1 column . means average of each element . Let say if I have 100 columns in my original data, it should give me 50 columns

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by