I'm trying to write a program that calculates the standard deviation of an array without using sum() or std() and I'm having problems
1 回表示 (過去 30 日間)
古いコメントを表示
Here is my code thus far; aberration_waves=[0.213 0.531 0.605 0.448 0.972 0.054 0.889 0.247 0.128 0.711]; N=numel(aberration_waves);
sum_x=0;
for k=aberration_waves
sum_x=sum_x+k;
end
xavg=sum_x/N;
sum_diff=-xavg;
for x=aberration_waves;
sum_diff=-xavg+x;
end
std=sqrt((sum_diff^2)/(N-1));
I have no problem with finding the average it's the standard deviation that is vexing me. Specifically sum_diff, it's not what it should be, I would appreciate some help
0 件のコメント
採用された回答
Youssef Khmou
2013 年 3 月 25 日
編集済み: Youssef Khmou
2013 年 3 月 25 日
hi, try :
aberration_waves=[0.213 0.531 0.605 0.448 0.972 0.054 0.889 0.247 0.128 0.711];
N=numel(aberration_waves);
sum_x=0;
for k=aberration_waves
sum_x=sum_x+k;
end
xavg=sum_x/N;
% STD
S=0;
for k=1:N
S=S+(aberration_waves(k)-xavg).^2;
end
VARIANCE=S/(N-1);
STD=sqrt(VARIANCE);
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Biotech and Pharmaceutical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!