MATLAB: Syntax help with script

scriptsyntax

I am wanting to put this equation into matlab, but I am having problems.
I am wanting to find the standard deviation without the built in matlab function. I have a mean_temp and a mean_pres already set up and displaying properly. Can I get some help how to incorporate those values (i have i=1:30) for each temp and pressure.
The standard deviation equation is:
(sum i=1 to n (xi^2-nxbar^2))/(n-1)
My xi should be my values each 1 through 30. xbar is my mean.
Thank you in advance.

Best Answer

assuming x is an nx1 column vector...
sum(x.^2-mean(x)^2)/size(x,1)
also I think your equation is wrong: http://en.wikipedia.org/wiki/Standard_deviation you'll want to square after subtracting, not before.
sum((x-mean(x)).^2)/size(x,1)
Related Question