How to subtract Mean from Matrix along columns
Mostrar comentarios más antiguos
Hi,
In subtraction, there is an example of subtract mean from matrix: A - mean(A) and it works well. But I have a matrix A of 15X1000, and I want to subtract the mean mean(A, 2) along the 1000 columns, how to do that? Thanks Jennifer
Respuesta aceptada
Más respuestas (2)
Just the same way, A-A_mean. Here's an example with 5 columns,
>>A = reshape(1:25,5,5) %dummydata
A =
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
>>A_mean = mean(A,2)
A_mean =
11
12
13
14
15
>>A = A-A_mean
A =
-10 -5 0 5 10
-10 -5 0 5 10
-10 -5 0 5 10
-10 -5 0 5 10
-10 -5 0 5 10
EDIT (thanks John)
and for older versions,
A = bsxfun(@minus,A,A_mean)
3 comentarios
John D'Errico
el 16 de Nov. de 2017
Editada: John D'Errico
el 16 de Nov. de 2017
+1, but note that this requires a recent release. I think that capability was introduced in R2017a. Otherwise, you will need to use a tool like repmat or bsxfun. It is clear that JFz has a sufficiently recent release, but others might see the post and expect it to work in an old release.
JFz
el 16 de Nov. de 2017
JFz
el 16 de Nov. de 2017
JFz
el 16 de Nov. de 2017
0 votos
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!