MATLAB: How to calculate the standard deviation of a LARGE set of values without using the’ std’ or ‘mean’ commands

hwstandard deviationstd

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 😀

Best Answer

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
Related Question