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.
"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
"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));
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Terms prior to use.