Computing the average across columns, while discounting a specific column

조회 수: 1 (최근 30일)
Ulrik William Nash
Ulrik William Nash 2018년 10월 13일
댓글: madhan ravi 2018년 10월 13일
What is the best way to compute the simple average across the columns of a matrix, when one of the columns must be completely discounted?

답변 (2개)

Stephen23
Stephen23 2018년 10월 13일
Say you have a matrix M and you want to get the mean of each row, ignoring the third column:
N = 3; % column to ignore
mean(M(:,[1:N-1,N+1:end]),2)

madhan ravi
madhan ravi 2018년 10월 13일
편집: madhan ravi 2018년 10월 13일
Not sure what you mean but a guess:
x=rand(4)
x(:,2)=[] %removes second column
mean(x,1)
  댓글 수: 2
Image Analyst
Image Analyst 2018년 10월 13일
This changes x, while Stephen's code doesn't change the matrix. Your code also gets the mean along rows (down rows in each column) instead of "across columns", though I'll admit it might be a bit ambiguous what "across columns" actually means.
madhan ravi
madhan ravi 2018년 10월 13일
ok @sir Image Analyst I was thinking to remove my answer anyway thank you for pointing the error :)

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

카테고리

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