MATLAB: When I do the standard deviation for the 2 arrays by hand I get a different answer than Matlab. Ive had 2 colleagues check and we all got the same answer; is there a problem with the code

standard deviation

year1_10 = [1460,1240,1230,1270,861,1355,612,822,1370,1380];
year11_20 = [810,735,259,1290,1125,528,622,468,664,717];
disp('The means of A and B are:')
mean(year1_10)
mean(year11_20)
w = 1;
disp('The standard deviation of A and B are:')
std2(year1_10)
std2(year11_20)

Best Answer

How can we possibly know if there is a problem with your code? You fail to show how you computed the standard deviation. std2 is not part of MATLAB itself, so did you write the code?
My guess is you divided by the number of elements in the array, instead of n-1.
year1_10 = [1460,1240,1230,1270,861,1355,612,822,1370,1380];
std(year1_10) % the default
ans =
288.265695342181
std(year1_10,1)
ans =
273.472850572045
The default method is the one that is usually appropriate. My guess is you used the alternative, as that is the common mistake made by people when they think there is an error.