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:
Finding variance of vector, discounting zeros.

Subject: Finding variance of vector, discounting zeros.

From: Ulrik Nash

Date: 16 Sep, 2011 15:23:29

Message: 1 of 4

Suppose I have a column vector, which includes zeros. How do I find the variance of all the numbers, discounting the zeros?

Regards,

Ulrik.

Subject: Finding variance of vector, discounting zeros.

From: Nasser M. Abbasi

Date: 16 Sep, 2011 15:38:57

Message: 2 of 4

On 9/16/2011 8:23 AM, Ulrik Nash wrote:
> Suppose I have a column vector, which includes zeros. How do I find the variance
>of all the numbers, discounting the zeros?
>
> Regards,
>
> Ulrik.

i am not good in statistics, but how about simply finding the variance
of all non-zero elements in the vector?


v=[1 2 3 0 4 0 8];

EDU>> var(v(v~=0))

ans =

     7.3000

--Nasser

Subject: Finding variance of vector, discounting zeros.

From: Wayne King

Date: 16 Sep, 2011 15:51:26

Message: 3 of 4

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j4vplh$8rc$1@newscl01ah.mathworks.com>...
> Suppose I have a column vector, which includes zeros. How do I find the variance of all the numbers, discounting the zeros?
>
> Regards,
>
> Ulrik.

Hi Ulrik, In addition to Nasser's suggestion, if you have the Statistics Toolbox, see nanvar() which has additional options, like the ability to add a weight vector.

Wayne

Subject: Finding variance of vector, discounting zeros.

From: Ulrik Nash

Date: 10 Nov, 2011 18:34:27

Message: 4 of 4

"Nasser M. Abbasi" <nma@12000.org> wrote in message <j4vqip$2ar$1@speranza.aioe.org>...
> On 9/16/2011 8:23 AM, Ulrik Nash wrote:
> > Suppose I have a column vector, which includes zeros. How do I find the variance
> >of all the numbers, discounting the zeros?
> >
> > Regards,
> >
> > Ulrik.
>
> i am not good in statistics, but how about simply finding the variance
> of all non-zero elements in the vector?
>
>
> v=[1 2 3 0 4 0 8];
>
> EDU>> var(v(v~=0))
>
> ans =
>
> 7.3000
>
> --Nasser


Suppose that I instead wish to calculate the variance of each column in a matrix, still disregarding zeros, how can I do that without the toolbox?

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