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 件のコメント
採用された回答
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 件のコメント
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 Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!