Average or mean of matrix elements


B = mean2(A)
gpuarrayB = mean2(gpuarrayA)


B = mean2(A) computes the mean of the values in A.

gpuarrayB = mean2(gpuarrayA) computes the mean of the values in gpuarrayA, performing the operation on a GPU. This syntax requires the Parallel Computing Toolbox™.

Code Generation support: Yes.

MATLAB Function Block support: Yes.

Class Support

The input image A can be numeric or logical. The output image B is a scalar of class double.

The input image gpuarrayA is a gpuArray whose underlying class is numeric or logical. The output image gpuarrayB is a gpuArray scalar with the underlying class double.


collapse all

Compute the mean of an image

Read image.

I = imread('liftingbody.png');

Compute mean.

val = mean2(I)
val =


More About

expand all

Code Generation

This function supports the generation of C code using MATLAB® Coder™. For more information, see Code Generation for Image Processing.

MATLAB Function Block

You can use this function in the MATLAB Function Block in Simulink.


mean2 computes the mean of an array A using mean(A(:)).

See Also

| |

Introduced before R2006a

Was this topic helpful?