Thread Subject: Which ML function for variance?

Subject: Which ML function for variance?

From: G.A.M.

Date: 2 Oct, 2007 15:04:16

Message: 1 of 4

I have two vectors. The element-by-element differences
represent an error quantity. I want to obtain the variance
(or square root) of these two vectors and I don't see a ML
function that will do this.

Here's what I'm doing right now:

differences = v1(ndx-rng:ndx+rng) - v2(ndx-rng:ndx+rng);
squaredDiffs = differences.^2;
sumSquares = sum(squaredDiffs);
result = sqrt (sumSquares / (length(squaredDiffs)-1) );

Is there a more efficient way to do this? Is there a single
ML function I can call that would do the same thing?

Thanks.

Subject: Which ML function for variance?

From: Adam

Date: 2 Oct, 2007 16:22:09

Message: 2 of 4

"G.A.M. " <x0zero@gmail.com> wrote in message
<fdtmlg$t1j$1@fred.mathworks.com>...
> I have two vectors. The element-by-element differences
> represent an error quantity. I want to obtain the variance
> (or square root) of these two vectors and I don't see a ML
> function that will do this.
>
> Here's what I'm doing right now:
>
> differences = v1(ndx-rng:ndx+rng) - v2(ndx-rng:ndx+rng);
> squaredDiffs = differences.^2;
> sumSquares = sum(squaredDiffs);
> result = sqrt (sumSquares / (length(squaredDiffs)-1) );
>
> Is there a more efficient way to do this? Is there a single
> ML function I can call that would do the same thing?
>
> Thanks.

std(), var()

you could locate these by opening help (F1) and searching
for variance, or typing

>> lookfor variance

~Adam

Subject: Which ML function for variance?

From: John D'Errico

Date: 2 Oct, 2007 17:07:00

Message: 3 of 4

"Adam " <not.my.email@mathworks.com> wrote in message <fdtr7h$2q9
$1@fred.mathworks.com>...
> "G.A.M. " <x0zero@gmail.com> wrote in message
> <fdtmlg$t1j$1@fred.mathworks.com>...
> > I have two vectors. The element-by-element differences
> > represent an error quantity. I want to obtain the variance
> > (or square root) of these two vectors and I don't see a ML
> > function that will do this.
> >
> > Here's what I'm doing right now:
> >
> > differences = v1(ndx-rng:ndx+rng) - v2(ndx-rng:ndx+rng);
> > squaredDiffs = differences.^2;
> > sumSquares = sum(squaredDiffs);
> > result = sqrt (sumSquares / (length(squaredDiffs)-1) );
> >
> > Is there a more efficient way to do this? Is there a single
> > ML function I can call that would do the same thing?
> >
> > Thanks.
>
> std(), var()
>
> you could locate these by opening help (F1) and searching
> for variance, or typing
>
> >> lookfor variance
>
> ~Adam

Actually, no. std and var both subtract off the mean
before squaring. The OP wishes to compute this
without the initial mean subtraction. In one line...

res = sqrt(sum(differences.^2/(length(differences)-1));

John

Subject: Which ML function for variance?

From: Peter Perkins

Date: 3 Oct, 2007 15:16:04

Message: 4 of 4

John D'Errico wrote:

> res = sqrt(sum(differences.^2/(length(differences)-1));

res = norm(differences)/sqrt(length(differences)-1);

would also work well.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
variance G.A.M. 2 Oct, 2007 11:05:04
sqrt G.A.M. 2 Oct, 2007 11:05:04
square root G.A.M. 2 Oct, 2007 11:05:04
errors G.A.M. 2 Oct, 2007 11:05:04
sum of squares G.A.M. 2 Oct, 2007 11:05:04
stats G.A.M. 2 Oct, 2007 11:05:04
rssFeed for this Thread

Contact us at files@mathworks.com