Help normalizing data in table

Hi,
I have a 100x6 Table with 6 variables. I want to center the data so that it has mean 0 and standard deviation 1, using the zscore.
I tried using this in the 3 variables of interest but is not working.
Normalized = normalize(data(:,1:3)));
If I try to convert the table to array then I loose the table information.
Thank you in advance!

 Respuesta aceptada

Dave B
Dave B el 3 de Dic. de 2021
Editada: Dave B el 3 de Dic. de 2021
When you want to work with multiple variables in a table at once, you have to use { } (this is because tables work with heterogenous data)
data=table(10*randn(100,1)+5, randn(100,1)/10, randn(100,1).^2);
ndata = data(:,1:3);
ndata{:,1:3} = normalize(ndata{:,1:3});
round(mean(table2array(ndata)),-10)
ans = 1×3
0 0 0
std(table2array(ndata))
ans = 1×3
1.0000 1.0000 1.0000

3 comentarios

Nina Perf
Nina Perf el 3 de Dic. de 2021
Editada: Nina Perf el 3 de Dic. de 2021
Thank you so much for the explaination! Why did you round the mean? The std is not 1 when I calculate it with your formula, but when I use zscore() function it is.
For the round bit - that's just because (after normalizing) the mean is close to zero, but not exactly zero. I rounded it to 10 digits. Here's what it looks like without the round:
data=table(10*randn(100,1)+5, randn(100,1)/10, randn(100,1).^2);
ndata = data(:,1:3);
ndata{:,1:3} = normalize(ndata{:,1:3});
mean(table2array(ndata))
ans = 1×3
1.0e+-15 * -0.0844 0.0266 -0.1821
So that's like -0.0000000000000000844 for the first one (I might have miscounted my zeros!)
I'm not sure what you mean by the std is not 1, can you give an example? (similar to the means, they're not exactly 1, but I'd think would be close to 1). Note that you can also use zscore in place of normalize, I just wanted to help with the 'how to apply it to table' bit...but I'd expect zscore and normalize to produce the same results...
Nina Perf
Nina Perf el 3 de Dic. de 2021
Editada: Nina Perf el 3 de Dic. de 2021
Thank you! The zscore function works well. However, the normalize function gives std close to 0..

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2021a

Preguntada:

el 3 de Dic. de 2021

Editada:

el 3 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by