# Mean of a vector

M = mean(A) returnsthe expect of the elementsof A along the initially range dimension whose sizedoes not equal 1.

You watching: Mean of a vector

If A is a vector, then mean(A) returnsthe mean of the facets.

If A is a matrix, then mean(A) returnsa row vector containing the mean of each column.

If A is a multidimensional range,then mean(A) opeprices alengthy the initially variety dimensionwhose size does not equal 1, dealing with the facets as vectors. Thisdimension becomes 1 while the sizes of all otherdimensions remajor the very same.

M = mean(A,"all") computes the suppose over all facets of A. This syntaxation is valid for MATLAB® versions R2018b and later.

M = mean(A,dim) returnsthe mean along dimension dim. For example, if A isa matrix, then mean(A,2) is a column vector containingthe suppose of each row.

M = mean(A,vecdim) computes the mean based upon the dimensions mentioned in the vector vecdim. For instance, if A is a matrix, then mean(A,<1 2>) is the intend of all elements in A, considering that eexceptionally aspect of a matrix is included in the selection slice characterized by dimensions 1 and also 2.

M = mean(___,outtype) returnsthe mean through a stated data form, utilizing any type of of the input argumentsin the previous syntaxes. outtype have the right to be "default", "double",or "native".

M = mean(___,nanflag) specifieswhether to incorporate or omit NaN worths from thecalculation for any type of of the previous syntaxes. mean(A,"includenan") includesall NaN values in the calculation while mean(A,"omitnan") ignoresthem.

Create a 4-by-2-by-3 array of integers between 1 and 10 and also compute the suppose values along the second dimension.

M = M(:,:,1) = 8.0000 5.5000 2.5000 8.0000M(:,:,2) = 10.0000 7.5000 5.5000 6.0000M(:,:,3) = 6.0000 5.5000 8.5000 10.0000
Starting in R2018b, to compute the mean over all dimensions of an range, you can either specify each measurement in the vector dimension argument, or use the "all" alternative.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | datetime | duration

Dimension to run alengthy, stated as a positive integer scalar. If no value is specified, then the default is the initially variety measurement whose size does not equal 1.

Dimension dim indicates the measurement whoselength reduces to 1. The size(M,dim) is 1,while the sizes of all other dimensions reprimary the exact same.

Consider a two-dimensional input variety, A.  mean retransforms A when dim isbetter than ndims(A) or as soon as size(A,dim) is 1.

Documents Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Vector of dimensions, stated as a vector of positive integers. Each element represents a measurement of the input range. The lengths of the output in the stated operating dimensions are 1, while the others remajor the same.

Consider a 2-by-3-by-3 input array, A. Then mean(A,<1 2>) returns a 1-by-1-by-3 array whose aspects are the means over each page of A. Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output data kind, mentioned as "default", "double",or "native". These choices additionally specify the dataform in which the operation is percreated.

outtypeOutput data type
"default"double, unmuch less the input data kind is single, duration,or datetime, in which instance, the output is "native"
"double"double, unmuch less the data form is duration or datetime,in which instance, "double" is not supported
"native"exact same data kind as the input, unmuch less

Input data type is logical, inwhich situation, the output is double