M = mean(A) returnsthe mean of the elementsof A along the first array dimension whose sizedoes not equal 1.

You are watching: Mean of a matrix matlab

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

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

If A is a multidimensional array,then mean(A) operates along the first array dimensionwhose size does not equal 1, treating the elements as vectors. Thisdimension becomes 1 while the sizes of all otherdimensions remain the same.

M = mean(A,"all") computes the mean over all elements of A. This syntax 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 mean of each row.

M = mean(A,vecdim) computes the mean based on the dimensions specified in the vector vecdim. For example, if A is a matrix, then mean(A,<1 2>) is the mean of all elements in A, since every element of a matrix is contained in the array slice defined by dimensions 1 and 2.

M = mean(___,outtype) returnsthe mean with a specified data type, using any of the input argumentsin the previous syntaxes. outtype can be "default", "double",or "native".

M = mean(___,nanflag) specifieswhether to include or omit NaN values from thecalculation for any 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 compute the mean 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 array, you can either specify each dimension in the vector dimension argument, or use the "all" option.

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

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

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

Consider a two-dimensional input array, A.  mean returns A when dim isgreater than ndims(A) or when size(A,dim) is 1.

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

Vector of dimensions, specified as a vector of positive integers. Each element represents a dimension of the input array. The lengths of the output in the specified operating dimensions are 1, while the others remain 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 elements are the means over each page of A.

See more: Always And Forever Jewlery, Best Value Always And Forever Necklace Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output data type, specified as "default", "double",or "native". These options also specify the datatype in which the operation is performed.

outtypeOutput data type
"default"double, unless the input data type is single, duration,or datetime, in which case, the output is "native"
"double"double, unless the data type is duration or datetime,in which case, "double" is not supported
"native"same data type as the input, unless

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