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 ビュー (過去 30 日間)
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)
  2 件のコメント
Star Strider
Star Strider 2020 年 1 月 4 日
What results do you and your colleagues get?
Amir Dagazau
Amir Dagazau 2020 年 1 月 4 日
we get:
273.47 and 286.78
whereas matlab returns:
288.2657 and 302.3713

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2020 年 1 月 4 日
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 件のコメント
Amir Dagazau
Amir Dagazau 2020 年 1 月 4 日
yes thank you both, I've amended my calculation. thanks again for the assistance.
Image Analyst
Image Analyst 2020 年 1 月 4 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by