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 my code?

15 vues (au cours des 30 derniers jours)
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)

Réponse acceptée

John D'Errico
John D'Errico le 4 Jan 2020
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.
  5 commentaires
Amir Dagazau
Amir Dagazau le 4 Jan 2020
yes thank you both, I've amended my calculation. thanks again for the assistance.
Image Analyst
Image Analyst le 4 Jan 2020
Please Accept this answer to give John reputation points for helping you, and to let others know the problem is already solved. Thanks in advance.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by