# var

Variance

## Syntax

## Description

returns the variance
of the elements of `V`

= var(`A`

)`A`

along the first array dimension whose size
is greater than 1. By default, the variance is normalized by `N-1`

,
where `N`

is the number of observations.

If

`A`

is a vector of observations, then`V`

is a scalar.If

`A`

is a matrix whose columns are random variables and whose rows are observations, then`V`

is a row vector containing the variance corresponding to each column.If

`A`

is a multidimensional array, then`var(A)`

operates along the first array dimension whose size is greater than 1, treating the elements as vectors. The size of`V`

in this dimension becomes`1`

, while the sizes of all other dimensions are the same as in`A`

.If

`A`

is a scalar, then`V`

is`0`

.If

`A`

is a`0`

-by-`0`

empty array, then`V`

is`NaN`

.If

`A`

is a table or timetable, then`var(A)`

returns a one-row table containing the variance of each variable.*(since R2023a)*

specifies a weighting scheme. When `V`

= var(`A`

,`w`

)`w = 0`

(default), the variance
is normalized by `N-1`

, where `N`

is the number of
observations. When `w = 1`

, the variance is normalized by the
number of observations. `w`

can also be a weight vector containing
nonnegative elements. In this case, the length of `w`

must equal
the length of the dimension over which `var`

is operating.

returns the variance over the dimensions specified in the vector
`V`

= var(`A`

,`w`

,`vecdim`

)`vecdim`

when `w`

is 0 or 1. For example, if
`A`

is a matrix, then `var(A,0,[1 2])`

returns
the variance over all elements in `A`

because every element of a
matrix is contained in the array slice defined by dimensions 1 and 2.

`[`

also returns the mean of the elements of `V`

,`M`

] = var(___)`A`

used to calculate the
variance. If `V`

is the weighted
variance, then `M`

is the weighted
mean.

## Examples

## Input Arguments

## Output Arguments

## More About

## Extended Capabilities

## Version History

**Introduced before R2006a**