Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Standard deviation

Subject: Standard deviation

From: Paul

Date: 28 Jan, 2013 14:25:08

Message: 1 of 4

Hi together,
i calculate the standard deviaton in MATLAB and to the check the results i reculculated manually in MATLAB and Excel and i got different results. I split the formula in MATLAB to calculate the individual terms and as result i have received the same as in Excel. Is there a known problem with the standard deviation in MATLAB?

My example:

test = -18.2264 -17.7185 -15.4258 -15.4092

mean_test = -16.6950 <<< mean_test= mean(test)

sqr = 278.7222 <<< sqr= mean_test^2

test_sqr = 332.2018 313.9459 237.9556 237.4423 <<< test_sqr= test.^2

diff = 53.4796 35.2237 -40.7666 -41.2799 <<< diff = bsxfun(@minus,test_sqr,sqr)

sum = 6.6568 <<< summe = sum(diff(:))

norm = 1.6642 <<< norm = 0.25*summe
 
final = 1.2900 <<< final = norm^0.5

my results

in Excel: 1.2901
in MATLAB (manually): 1.2900
 in MATLAB (with "stdev"): 1.0931

Can someone explain this to me?

Thanks,Paul

Subject: Standard deviation

From: Jos (10584)

Date: 28 Jan, 2013 14:42:06

Message: 2 of 4

"Paul " <paulrockt@gmx.de> wrote in message <ke61o4$4n8$1@newscl01ah.mathworks.com>...
> Hi together,
> i calculate the standard deviaton in MATLAB and to the check the results i reculculated manually in MATLAB and Excel and i got different results. I split the formula in MATLAB to calculate the individual terms and as result i have received the same as in Excel. Is there a known problem with the standard deviation in MATLAB?
>
> My example:
>
> test = -18.2264 -17.7185 -15.4258 -15.4092
>
> mean_test = -16.6950 <<< mean_test= mean(test)
>
> sqr = 278.7222 <<< sqr= mean_test^2
>
> test_sqr = 332.2018 313.9459 237.9556 237.4423 <<< test_sqr= test.^2
>
> diff = 53.4796 35.2237 -40.7666 -41.2799 <<< diff = bsxfun(@minus,test_sqr,sqr)
>
> sum = 6.6568 <<< summe = sum(diff(:))
>
> norm = 1.6642 <<< norm = 0.25*summe
>
> final = 1.2900 <<< final = norm^0.5
>
> my results
>
> in Excel: 1.2901
> in MATLAB (manually): 1.2900
> in MATLAB (with "stdev"): 1.0931
>
> Can someone explain this to me?
>
> Thanks,Paul

From the help of STD
" STD normalizes Y by (N-1), where N is the sample size. This is the
    sqrt of an unbiased estimator of the variance of the population from
    which X is drawn, as long as X consists of independent, identically
    distributed samples.
 
    Y = STD(X,1) normalizes by N and produces the square root of the second
    moment of the sample about its mean.
"
Indeed, for your example, std(test,1) gives 1.29 ...

For more info see
  doc std
and
  http://en.wikipedia.org/wiki/Standard_deviation


hth
~ Jos

Subject: Standard deviation

From: Torsten

Date: 28 Jan, 2013 14:50:08

Message: 3 of 4

"Paul " <paulrockt@gmx.de> wrote in message <ke61o4$4n8$1@newscl01ah.mathworks.com>...
> Hi together,
> i calculate the standard deviaton in MATLAB and to the check the results i reculculated manually in MATLAB and Excel and i got different results. I split the formula in MATLAB to calculate the individual terms and as result i have received the same as in Excel. Is there a known problem with the standard deviation in MATLAB?
>
> My example:
>
> test = -18.2264 -17.7185 -15.4258 -15.4092
>
> mean_test = -16.6950 <<< mean_test= mean(test)
>
> sqr = 278.7222 <<< sqr= mean_test^2
>
> test_sqr = 332.2018 313.9459 237.9556 237.4423 <<< test_sqr= test.^2
>
> diff = 53.4796 35.2237 -40.7666 -41.2799 <<< diff = bsxfun(@minus,test_sqr,sqr)
>
> sum = 6.6568 <<< summe = sum(diff(:))
>
> norm = 1.6642 <<< norm = 0.25*summe
>
> final = 1.2900 <<< final = norm^0.5
>
> my results
>
> in Excel: 1.2901
> in MATLAB (manually): 1.2900
> in MATLAB (with "stdev"): 1.0931
>
> Can someone explain this to me?
>
> Thanks,Paul

1. I only know of the command "std" in MATLAB.
2. Usually, the above variable "norm" is calculated according to norm=1/3*summe.

Instead of the stepwise calculation from above, provide your MATLAB code -
it's easier to follow.

Best wishes
Torsten.

Subject: Standard deviation

From: Paul

Date: 28 Jan, 2013 15:15:07

Message: 4 of 4

"Jos (10584)" wrote in message <ke62nu$958$1@newscl01ah.mathworks.com>...
> "Paul " <paulrockt@gmx.de> wrote in message <ke61o4$4n8$1@newscl01ah.mathworks.com>...
> > Hi together,
> > i calculate the standard deviaton in MATLAB and to the check the results i reculculated manually in MATLAB and Excel and i got different results. I split the formula in MATLAB to calculate the individual terms and as result i have received the same as in Excel. Is there a known problem with the standard deviation in MATLAB?
> >
> > My example:
> >
> > test = -18.2264 -17.7185 -15.4258 -15.4092
> >
> > mean_test = -16.6950 <<< mean_test= mean(test)
> >
> > sqr = 278.7222 <<< sqr= mean_test^2
> >
> > test_sqr = 332.2018 313.9459 237.9556 237.4423 <<< test_sqr= test.^2
> >
> > diff = 53.4796 35.2237 -40.7666 -41.2799 <<< diff = bsxfun(@minus,test_sqr,sqr)
> >
> > sum = 6.6568 <<< summe = sum(diff(:))
> >
> > norm = 1.6642 <<< norm = 0.25*summe
> >
> > final = 1.2900 <<< final = norm^0.5
> >
> > my results
> >
> > in Excel: 1.2901
> > in MATLAB (manually): 1.2900
> > in MATLAB (with "stdev"): 1.0931
> >
> > Can someone explain this to me?
> >
> > Thanks,Paul
>
> From the help of STD
> " STD normalizes Y by (N-1), where N is the sample size. This is the
> sqrt of an unbiased estimator of the variance of the population from
> which X is drawn, as long as X consists of independent, identically
> distributed samples.
>
> Y = STD(X,1) normalizes by N and produces the square root of the second
> moment of the sample about its mean.
> "
> Indeed, for your example, std(test,1) gives 1.29 ...
>
> For more info see
> doc std
> and
> http://en.wikipedia.org/wiki/Standard_deviation
>
>
> hth
> ~ Jos

Hi Jos,
thank you, your answer helped me. My problem is solved!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us