How can I calculate the standard deviation of a LARGE set of values without using the' std' or 'mean' commands?

6 visualizaciones (últimos 30 días)
I tried entering
endStandDevx = sqrt(sum((x-(AvgX))).^2/(length(x))
(since we can't use mean I found the average by finding sum over total # of vals)
However, this line gives me a far different value than
std(x)
and i'm not really sure why...
Any help would be lovely :D

Respuesta aceptada

James Tursa
James Tursa el 1 de Nov. de 2016
Editada: James Tursa el 1 de Nov. de 2016
You've got the ^2 in the wrong place in your calculation. Also, the std function uses n-1 in the denominator by default. Try this:
>> x = rand(1,10000);
>> AvgX = sum(x)/length(x);
>> endStandDevx = sqrt(sum((x-AvgX).^2)/(length(x)-1))
endStandDevx =
0.2895
>> std(x)
ans =
0.2895
  2 comentarios
Paul Camerino
Paul Camerino el 1 de Nov. de 2016
AWESOME! Thanks so much, mate. That really helped. I guess my parentheses and everything was just way out of whack, so your direction really helped and gave me the correct value. Thanks so much!
James Tursa
James Tursa el 1 de Nov. de 2016
Sometimes it can greatly help when you put spaces within your line to make the parentheses separations more obvious.

Iniciar sesión para comentar.

Más respuestas (1)

Adam
Adam el 1 de Nov. de 2016
Editada: Adam el 1 de Nov. de 2016
std divides by n-1 rather than n. You didn't post what kind of difference you are getting so I don't know if that is the only difference but it will be a difference, obviously less noticeable with a bigger sample size though. Since you say your result is far away and your sample size is large I assume this is not the only issue.
Is your average calculation correct and matching the output of mean?
The formula for std is on its help page
doc std

Categorías

Más información sobre Parallel Computing Toolbox 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