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:
Variance of all values in a matrix

Subject: Variance of all values in a matrix

From: Ulrik Nash

Date: 18 Nov, 2011 21:02:28

Message: 1 of 12

Is there an expression for finding the variance of all elements in a matrix? If so, what is it?

Subject: Variance of all values in a matrix

From: ade77

Date: 18 Nov, 2011 21:15:29

Message: 2 of 12

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <ja6h54$8d9$1@newscl01ah.mathworks.com>...
> Is there an expression for finding the variance of all elements in a matrix? If so, what is it?

doc var

Subject: Variance of all values in a matrix

From: Ulrik Nash

Date: 18 Nov, 2011 21:25:11

Message: 3 of 12

"ade77 " <ade100a@gmail.com> wrote in message <ja6hth$b2b$1@newscl01ah.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <ja6h54$8d9$1@newscl01ah.mathworks.com>...
> > Is there an expression for finding the variance of all elements in a matrix? If so, what is it?
>
> doc var

I was hoping the doc was incomplete. I need the variance not simply of a row or column, but for all values at once. Surely MatLab can do this, right?

Subject: Variance of all values in a matrix

From: Steven_Lord

Date: 18 Nov, 2011 21:26:17

Message: 4 of 12



"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
news:ja6ifn$d33$1@newscl01ah.mathworks.com...
> "ade77 " <ade100a@gmail.com> wrote in message
> <ja6hth$b2b$1@newscl01ah.mathworks.com>...
>> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
>> <ja6h54$8d9$1@newscl01ah.mathworks.com>...
>> > Is there an expression for finding the variance of all elements in a
>> > matrix? If so, what is it?
>>
>> doc var
>
> I was hoping the doc was incomplete. I need the variance not simply of a
> row or column, but for all values at once. Surely MatLab can do this,
> right?

Columnize the matrix.

A = magic(7);
var(A(:))

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Variance of all values in a matrix

From: Ulrik Nash

Date: 18 Nov, 2011 21:31:14

Message: 5 of 12

"Steven_Lord" <slord@mathworks.com> wrote in message <ja6ihp$dam$1@newscl01ah.mathworks.com>...
>
>
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
> news:ja6ifn$d33$1@newscl01ah.mathworks.com...
> > "ade77 " <ade100a@gmail.com> wrote in message
> > <ja6hth$b2b$1@newscl01ah.mathworks.com>...
> >> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
> >> <ja6h54$8d9$1@newscl01ah.mathworks.com>...
> >> > Is there an expression for finding the variance of all elements in a
> >> > matrix? If so, what is it?
> >>
> >> doc var
> >
> > I was hoping the doc was incomplete. I need the variance not simply of a
> > row or column, but for all values at once. Surely MatLab can do this,
> > right?
>
> Columnize the matrix.
>
> A = magic(7);
> var(A(:))

Thank you very much, Steve. That really should be in the documentation.

Subject: Variance of all values in a matrix

From: Roger Stafford

Date: 18 Nov, 2011 21:33:11

Message: 6 of 12

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <ja6h54$8d9$1@newscl01ah.mathworks.com>...
> Is there an expression for finding the variance of all elements in a matrix? If so, what is it?
- - - - - - - -
  If M is your matrix, do:

 v = var(M(:));

Roger Stafford

Subject: Variance of all values in a matrix

From: Ulrik Nash

Date: 18 Nov, 2011 21:36:28

Message: 7 of 12

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <ja6ir2$e6k$1@newscl01ah.mathworks.com>...
> "Steven_Lord" <slord@mathworks.com> wrote in message <ja6ihp$dam$1@newscl01ah.mathworks.com>...
> >
> >
> > "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
> > news:ja6ifn$d33$1@newscl01ah.mathworks.com...
> > > "ade77 " <ade100a@gmail.com> wrote in message
> > > <ja6hth$b2b$1@newscl01ah.mathworks.com>...
> > >> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
> > >> <ja6h54$8d9$1@newscl01ah.mathworks.com>...
> > >> > Is there an expression for finding the variance of all elements in a
> > >> > matrix? If so, what is it?
> > >>
> > >> doc var
> > >
> > > I was hoping the doc was incomplete. I need the variance not simply of a
> > > row or column, but for all values at once. Surely MatLab can do this,
> > > right?
> >
> > Columnize the matrix.
> >
> > A = magic(7);
> > var(A(:))
>
> Thank you very much, Steve. That really should be in the documentation.


On the other hand, I really should have known about columnize. If I did, the rest would have been obvious! :)

Subject: Variance of all values in a matrix

From: Ulrik Nash

Date: 18 Nov, 2011 21:37:11

Message: 8 of 12

"Roger Stafford" wrote in message <ja6iun$ejc$1@newscl01ah.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <ja6h54$8d9$1@newscl01ah.mathworks.com>...
> > Is there an expression for finding the variance of all elements in a matrix? If so, what is it?
> - - - - - - - -
> If M is your matrix, do:
>
> v = var(M(:));
>
> Roger Stafford

Thank you Roger..

Subject: Variance of all values in a matrix

From: Steven_Lord

Date: 18 Nov, 2011 21:37:21

Message: 9 of 12



"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
news:ja6ir2$e6k$1@newscl01ah.mathworks.com...
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <ja6ihp$dam$1@newscl01ah.mathworks.com>...
>>
>>
>> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
>> news:ja6ifn$d33$1@newscl01ah.mathworks.com...
>> > "ade77 " <ade100a@gmail.com> wrote in message
>> > <ja6hth$b2b$1@newscl01ah.mathworks.com>...
>> >> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
>> >> <ja6h54$8d9$1@newscl01ah.mathworks.com>...
>> >> > Is there an expression for finding the variance of all elements in a
>> >> > matrix? If so, what is it?
>> >>
>> >> doc var
>> >
>> > I was hoping the doc was incomplete. I need the variance not simply of
>> > a row or column, but for all values at once. Surely MatLab can do this,
>> > right?
>>
>> Columnize the matrix.
>>
>> A = magic(7);
>> var(A(:))
>
> Thank you very much, Steve. That really should be in the documentation.

It is. Take a look at the "Specifying All Elements of a Row or Column"
section on this page.

http://www.mathworks.com/help/techdoc/math/f1-85462.html#f1-85544

Should it be included more _prominently_ (or in another location or more
locations) in the documentation? Perhaps. Can you tell me where you'd expect
to see that information?

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Variance of all values in a matrix

From: Ulrik Nash

Date: 18 Nov, 2011 22:26:11

Message: 10 of 12

"Steven_Lord" <slord@mathworks.com> wrote in message <ja6j6h$fb2$1@newscl01ah.mathworks.com>...
>
>
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
> news:ja6ir2$e6k$1@newscl01ah.mathworks.com...
> > "Steven_Lord" <slord@mathworks.com> wrote in message
> > <ja6ihp$dam$1@newscl01ah.mathworks.com>...
> >>
> >>
> >> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
> >> news:ja6ifn$d33$1@newscl01ah.mathworks.com...
> >> > "ade77 " <ade100a@gmail.com> wrote in message
> >> > <ja6hth$b2b$1@newscl01ah.mathworks.com>...
> >> >> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
> >> >> <ja6h54$8d9$1@newscl01ah.mathworks.com>...
> >> >> > Is there an expression for finding the variance of all elements in a
> >> >> > matrix? If so, what is it?
> >> >>
> >> >> doc var
> >> >
> >> > I was hoping the doc was incomplete. I need the variance not simply of
> >> > a row or column, but for all values at once. Surely MatLab can do this,
> >> > right?
> >>
> >> Columnize the matrix.
> >>
> >> A = magic(7);
> >> var(A(:))
> >
> > Thank you very much, Steve. That really should be in the documentation.
>
> It is. Take a look at the "Specifying All Elements of a Row or Column"
> section on this page.
>
> http://www.mathworks.com/help/techdoc/math/f1-85462.html#f1-85544
>
> Should it be included more _prominently_ (or in another location or more
> locations) in the documentation? Perhaps. Can you tell me where you'd expect
> to see that information?
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


I think it would be a good idea to mention, perhaps to conclude the section on variance, that columnizing combined with the use of variance, permits the calculation of variance for the entire matrix at once.

Subject: Variance of all values in a matrix

From: Matt J

Date: 18 Nov, 2011 22:45:16

Message: 11 of 12

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <ja6m23$obv$1@newscl01ah.mathworks.com>...
>
>
> I think it would be a good idea to mention, perhaps to conclude the section on variance, that columnizing combined with the use of variance, permits the calculation of variance for the entire matrix at once.
=================

Unless you propose to do the same for the documentation sections of all the other reductions (MIN, MAX, SUM, MEAN, ANY,ALL, etc...), I would see that as treating the documentation on VAR a bit too sacredly.

Perhaps, though, they could conclude the section on the ':' operator

http://www.mathworks.com/help/techdoc/math/f1-85462.html#f1-85544

with examples like var(A(:)), min(A(:)), etc...

Subject: Variance of all values in a matrix

From: dpb

Date: 18 Nov, 2011 22:54:40

Message: 12 of 12

On 11/18/2011 3:36 PM, Ulrik Nash wrote:
...

>> Thank you very much, Steve. That really should be in the documentation.

It is in handling matrices, at least.

If you mean to add it to the doc's for a particular function (var in
this case), you then would need it in every function that works
similarly. That makes no sense.

> On the other hand, I really should have known about columnize. If I did,
> the rest would have been obvious! :)

Indeed, that's why folks are told so frequently to work their way
through the Getting Started sections--it's the place to see those
"tricks" in action early on.

--

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