Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
98 views

Variance - MATLAB Var

Var returns the variance of the elements in an input array A along the first dimension whose size does not equal 1. It can operate on vectors, matrices, and multidimensional arrays. The variance is normalized by the number of observations minus 1 by default. Var allows specifying a weighting scheme, dimension to operate along, and whether to include or exclude NaN values.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

Variance - MATLAB Var

Var returns the variance of the elements in an input array A along the first dimension whose size does not equal 1. It can operate on vectors, matrices, and multidimensional arrays. The variance is normalized by the number of observations minus 1 by default. Var allows specifying a weighting scheme, dimension to operate along, and whether to include or exclude NaN values.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

var

Variance

Syntax
V=var(A)

example

V=var( ___ ,w)

example

V=var( ___ ,dim)

example

V=var( ___ ,nanflag)

example

Description
V=var(A)returnsthevarianceoftheelementsofAalongthefirstarraydimensionwhose
sizedoesnotequal1.

IfAisavectorofobservations,thevarianceisascalar.

IfAisamatrixwhosecolumnsarerandomvariablesandwhoserowsareobservations,Vis
arowvectorcontainingthevariancescorrespondingtoeachcolumn.

IfAisamultidimensionalarray,thenvar(A)treatsthevaluesalongthefirstarray
dimensionwhosesizedoesnotequal1asvectors.Thesizeofthisdimensionbecomes1
whilethesizesofallotherdimensionsremainthesame.

Thevarianceisnormalizedbythenumberofobservations1bydefault.

IfAisascalar,var(A)returns0.IfAisa0by0emptyarray,var(A)returnsNaN.

example

V=var( ___ ,w)specifiesaweightingschemeforanyoftheprevioussyntaxes.Whenw=0


(default),Visnormalizedbythenumberofobservations1.Whenw=1,itisnormalizedbythe
numberofobservations.wcanalsobeaweightvectorcontainingnonnegativeelements.Inthis
case,thelengthofwmustequalthelengthofthedimensionoverwhichvarisoperating.

example

V=var( ___ ,dim)returnsthevariancealongthedimensiondimforanyoftheprevious


syntaxes.Tomaintainthedefaultnormalizationwhilespecifyingthedimensionofoperation,set
w=0inthesecondargument.

example

V=var( ___ ,nanflag)specifieswhethertoincludeoromitNaNvaluesfromthecalculationfor


anyoftheprevioussyntaxes.Forexample,var(A,'includenan')includesallNaNvaluesinA
whilevar(A,'omitnan')ignoresthem.

example

Examples

collapseall

VarianceofMatrix
Createamatrixandcomputeitsvariance.

A=[473;142;1079];
var(A)
ans=
21.000054.333330.3333

OpenThisExample

VarianceofArray
Createa3Darrayandcomputeitsvariance.

OpenThisExample

A(:,:,1)=[13;84];
A(:,:,2)=[34;12];
var(A)
ans(:,:,1)=
24.50000.5000

ans(:,:,2)=
218

SpecifyVarianceWeightVector
Createamatrixandcomputeitsvarianceaccordingtoaweightvectorw.

OpenThisExample

A=[546;239;112];
w=[0.50.250.25];
var(A,w)
ans=
6.18759.50006.1875

SpecifyDimensionforVariance
Createamatrixandcomputeitsvariancealongthefirstdimension.

A=[421;957];
var(A,0,1)
ans=
12.500024.500018.0000
ComputethevarianceofAalongtheseconddimension.
var(A,0,2)
ans=
9
4

OpenThisExample

VarianceExcludingNaN
Createavectorandcomputeitsvariance,excludingNaNvalues.

OpenThisExample

A=[1.770.0053.982.95NaN0.34NaN0.19];
V=var(A,'omitnan')
V=
5.1970

InputArguments

collapseall

AInputarray
vector|matrix|multidimensionalarray
Inputarray,specifiedasavector,matrix,ormultidimensionalarray.
DataTypes:single|double
ComplexNumberSupport:Yes
wWeight
0(default)|1|vector
Weight,specifiedasoneof:

0normalizesbythenumberofobservations1.Ifthereisonlyoneobservation,theweightis1.

1normalizesbythenumberofobservations.

avectormadeupofnonnegativescalarweightscorrespondingtothedimensionofAalongwhichthe
varianceiscalculated.

DataTypes:single|double
dimDimensiontooperatealong
positiveintegerscalar
Dimensiontooperatealong,specifiedasapositiveintegerscalar.Ifnovalueisspecified,thenthedefault
isthefirstarraydimensionwhosesizedoesnotequal1.
Dimensiondimindicatesthedimensionwhoselengthreducesto1.Thesize(V,dim)is1,whilethesizes
ofallotherdimensionsremainthesame.
Consideratwodimensionalinputarray,A.

Ifdim=1,thenvar(A,0,1)returnsarowvectorcontainingthevarianceoftheelementsineach
column.

Ifdim=2,thenvar(A,0,2)returnsacolumnvectorcontainingthevarianceoftheelementsineach
row.

varreturnsanarrayofzerosthesamesizeasAwhendimisgreaterthanndims(A).
DataTypes:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64
nanflagNaNcondition
includenan'(default)|omitnan'
NaNcondition,specifiedasoneofthesevalues:

includenan'thevarianceofinputcontainingNaNvaluesisalsoNaN.

omitnan'allNaNvaluesappearingineithertheinputarrayorweightvectorareignored.

DataTypes:char

MoreAbout

collapseall

Variance
ForarandomvariablevectorAmadeupofNscalarobservations,thevarianceisdefinedas
1
N 1

V =

i =1

Ai

whereisthemeanofA,

1
N

i =1

Ai .

SomedefinitionsofvarianceuseanormalizationfactorofNinsteadofN1,whichcanbespecifiedby
settingwto1.Ineithercase,themeanisassumedtohavetheusualnormalizationfactorN.

SeeAlso
corrcoef|cov|mean|std

IntroducedbeforeR2006a

You might also like