Main Content

mean

Average or mean value of fixed-point array

Description

M = mean(A) computes the mean value of the real-valued fixed-point array A along its first nonsingleton dimension.

example

M = mean(A,dim) computes the mean value of the real-valued fixed-point array A along dimension dim. dim must be a positive, real-valued integer with a power-of-two slope and a bias of 0.

The fixed-point output array, M, has the same numerictype properties as the fixed-point input array, A.

If the input array, A, has a local fimath, then it is used for intermediate calculations. The output, M, is always associated with the default fimath.

When A is an empty fixed-point array (value = []), the value of the output array is zero.

example

Examples

collapse all

Create a matrix and compute the mean of each column. A is a signed fi object with a 32-bit word length and a best-precision fraction length of 28 bits.

A = fi([0 1 2; 3 4 5],1,32);
M = mean(A)
A = 

     0     1     2
     3     4     5

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 32
        FractionLength: 28

M = 

    1.5000    2.5000    3.5000

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 32
        FractionLength: 28

Create a matrix and compute the mean of each row. A is a signed fi object with a 32-bit word length and a best-precision fraction length of 28 bits.

A = fi([0 1 2; 3 4 5],1,32)
M = mean(A,2)
A = 

     0     1     2
     3     4     5

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 32
        FractionLength: 28

M = 

     1
     4

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 32
        FractionLength: 28

Input Arguments

collapse all

Input array, specified as a vector, matrix, or multidimensional array.

  • If A is a scalar, then mean(A) returns A.

  • If A is an empty fixed-point array (value = []), the value of the output array is zero.

Data Types: fi

Dimension to operate along, specified as a positive, real-valued, integer scalar with a power-of-two slope and a bias of 0. If no value is specified, then the default is the first array dimension whose size does not equal 1.

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

Algorithms

The general equation for computing the mean of an array A, across dimension dim is:

sum(A,dim)/size(A,dim)

Because size(a,dim) is always a positive integer, the algorithm for computing mean casts size(A,dim) to an unsigned 32-bit fi object with a fraction length of zero (denote this fi object 'SizeA'). The algorithm then computes the mean of A according to the following equation, where Tx represents the numerictype properties of the fixed-point input array A:

c = Tx.divide(sum(A,dim), SizeA)

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2010a

See Also

| |