Mean of Matrix Rows

14 views (last 30 days)
Vince Smith
Vince Smith on 18 May 2019
Commented: Star Strider on 22 Aug 2021
For any matrix A, how would I subtract the row means from each row, so that each row has a mean of zero?

Accepted Answer

Star Strider
Star Strider on 18 May 2019
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
Star Strider
Star Strider on 22 Aug 2021
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).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by