This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


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

Read an image into the workspace.

I = imread('liftingbody.png');

Compute the mean.

meanval = mean2(I)
meanval =


More About

collapse 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?