필터 지우기
필터 지우기

Mean of Matrix Rows

조회 수: 2 (최근 30일)
Vince Smith
Vince Smith 2019년 5월 18일
댓글: Star Strider 2021년 8월 22일
For any matrix A, how would I subtract the row means from each row, so that each row has a mean of zero?

채택된 답변

Star Strider
Star Strider 2019년 5월 18일
The row means would be calculated as the mean of dimension 2.
Try this:
A = rand(5);
Anew = A - mean(A,2);
Check = mean(Anew,2) % Confirm: Mean = 0
  댓글 수: 2
Yugal Kishore
Yugal Kishore 2021년 8월 22일
sorry for activating this old thread but proved quite useful.
If I need to do a column means for the same problem statement, how would I do that. One way is to do a transpose of the matrix. I couldn't find anything in the documentataion.
Star Strider
Star Strider 2021년 8월 22일
No worries!
To do column means, use mean without any extra arguments (it defaults to taking the column means), or specifying 1 as the dimension (instead of 2).
.

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

추가 답변 (0개)

카테고리

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