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)

채택된 답변

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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by