Borrar filtros
Borrar filtros

How to center vector to mean zero?

39 visualizaciones (últimos 30 días)
gsourop
gsourop el 9 de Nov. de 2017
Respondida: John D'Errico el 9 de Nov. de 2017
Hi everyone,
I would like to center a vector A = randn(50,1) to center, meaning that (1/N)*sum(a(i)) = 0 , where a is the centered vector A, i = 1, .. ,50 and n=50. Moreover, if I have a matrix B = randn(50,4) how could we standardize it, meaning that (1/n)*sum(x(i))=0 and (1/n)*sum(x^2)=1, namely they follow a normal distribution with zero mean and unit variance N(0,1). Could anyone help with these two problems?
  1 comentario
Rik
Rik el 9 de Nov. de 2017
You mean something like x=x-mean(x);? You notation isn't very clear, nor what it precisely is you want to do.

Iniciar sesión para comentar.

Respuesta aceptada

John D'Errico
John D'Errico el 9 de Nov. de 2017
Standardize a vector, by centering to have mean 0, and variance 1.
x = rand(100,1);
x = (x-mean(x))/std(x);
Subtracting the mean centers it. Dividing by the standard deviation is independent of the mean, but it sets the standard deviation (and thus the variance) to 1.
mean(x)
ans =
7.6605e-17
std(x)
ans =
1
var(x)
ans =
1
The population parameters are as close to 0 and 1 as floating point computations can ensure.

Más respuestas (0)

Categorías

Más información sobre Preprocessing Data en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by