M = mean(A) returnsthe mean of the elementsof A alengthy the initially variety measurement whose sizedoes not equal 1.

You are watching: Average of an array matlab

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

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

If A is a multidimensional variety,then mean(A) operates along the first selection dimensionwhose dimension does not equal 1, treating the elements as vectors. Thismeasurement becomes 1 while the sizes of all otherdimensions remajor the exact same.

M = mean(A,"all") computes the expect over all aspects of A. This syntax is valid for MATLAB® versions R2018b and also later on.

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

M = mean(A,vecdim) computes the expect based upon the dimensions stated in the vector vecdim. For example, if A is a matrix, then mean(A,<1 2>) is the mean of all aspects in A, considering that every element of a matrix is had in the variety slice identified by dimensions 1 and also 2.

M = mean(___,outtype) returnsthe expect via a specified data kind, making use of any kind of of the input argumentsin the previous syntaxes. outkind can 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 also 10 and also compute the intend 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 expect over all dimensions of an array, you deserve to either specify each measurement in the vector dimension debate, or usage the "all" option.

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

Dimension to operate alengthy, specified as a positive integer scalar. If no value is mentioned, then the default is the first variety dimension whose dimension does not equal 1.

Dimension dim suggests the dimension whoselength reduces to 1. The size(M,dim) is 1,while the sizes of all other dimensions remain the exact same.

Consider a two-dimensional input variety, A.  intend returns A when dim isgreater than ndims(A) or as soon as size(A,dim) is 1.

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

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

Consider a 2-by-3-by-3 input array, A. Then mean(A,<1 2>) returns a 1-by-1-by-3 range whose elements are the means over each page of A.

See more: Micheal B Jordan And Nick Cannon Michael B Jordan, Interchangeable Celebs File Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

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

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

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