Quantcast
Viewing all articles
Browse latest Browse all 26

Re: Finding the mean and std using loops

Hey, I double checked with: https://www.easycalculation.com/statistics/standard-deviation.php
this is the correct way to get mean and sd using for loops.
Although I'm using different values (I was assigned a similar problem) the method should work for any set.


n=6; %number of terms
MEAN=0;
for x=[1 3 4 8 10 15] %given values
    spec = x/n;
    MEAN = spec+MEAN;
end

SUM=0;
for x=[1 3 4 8 10 15]
    difference = (x-MEAN)^2;
    SUM = difference + SUM;
end
    SD = sqrt(SUM/(n-1));


    fprintf('Mean = %g\nSD = %g',MEAN,SD)

Viewing all articles
Browse latest Browse all 26

Trending Articles