Documentation

### This is machine translation

Mouseover text to see original. Click the button below to return to the English version of the page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

# mean2

Average or mean of matrix elements

## Syntax

``B = mean2(A)``

## Description

example

````B = mean2(A)` computes the mean of all values in array `A`.You optionally can compute the mean using a GPU (requires Parallel Computing Toolbox™). For more information, see Image Processing on a GPU.```

## Examples

collapse all

Read an image into the workspace.

`I = imread('liftingbody.png');`

Compute the mean.

`meanval = mean2(I)`
```meanval = 140.2991 ```

Read a grayscale image into the workspace as a `gpuArray` object, then calculate the mean of the pixel intensity values using a GPU.

```I = gpuArray(imread('liftingbody.png')); meanval = mean2(I)```

## Input Arguments

collapse all

Input data, specified as a numerical or logical array.

To perform the computation using a GPU, specify `A` as a `gpuArray` that contains a numeric or logical array.

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

## Output Arguments

collapse all

Mean of input data, returned as a numeric scalar. If the data type of `A` is `single`, then the data type of `B` is also single. Otherwise, the data type of `B` is `double`.

If the image mean is computed using a GPU, then `B` is returned as a `gpuArray` containing a numeric scalar.

Data Types: `single` | `double`