Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Which ML function for variance?
Date: Tue, 2 Oct 2007 17:07:00 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 37
Message-ID: <fdttrj$p62$1@fred.mathworks.com>
References: <fdtmlg$t1j$1@fred.mathworks.com> <fdtr7h$2q9$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-06-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1191344820 25794 172.30.248.36 (2 Oct 2007 17:07:00 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 2 Oct 2007 17:07:00 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:431045



"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