Mean
Find mean value of input or sequence of inputs
 Library:
DSP System Toolbox / Statistics
Description
The Mean block computes the mean of each row or column of the input, or along vectors of a specified dimension of the input. It can also compute the mean of the entire input. You can specify the dimension using the Find the mean value over parameter. The Mean block can also track the mean value in a sequence of inputs over a period of time. To track the mean value in a sequence of inputs, select the Running mean parameter.
Note
The Running mode in the Mean block will be removed in a future release. To compute the running mean in Simulink^{®}, use the Moving Average block instead.
Ports
Input
I
— Data input
vector  matrix  ND array
The block accepts realvalued or complexvalued multichannel and multidimensional inputs. The input data type must be double precision, single precision, integer, or fixed point with poweroftwo slope and zero bias.
This port is unnamed until you select the Running
mean parameter and set the Reset
port parameter to any option other than
None
.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
Complex Number Support: Yes
Rst
— Reset port
scalar
Specify the reset event that causes the block to reset the running mean. The sample time of the Rst input must be a positive integer multiple of the input sample time.
Dependencies
To enable this port, select the Running mean
parameter and set the Reset port parameter to
any option other than None
.
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
 Boolean
Output
Port_1
— Mean value along the specified dimension
scalar  vector  matrix  ND array
The data type of the output matches the data type of the input.
When you do not select the Running mean
parameter, the block computes the mean value in each row or column of
the input, or along vectors of a specified dimension of the input. It
can also compute the mean of the entire input at each individual sample
time. Each element in the output array y
is the mean
value of the corresponding column, row, or entire input. The output
array y
depends on the setting of the Find
the mean value over parameter. Consider a
threedimensional input signal of size
MbyNbyP.
When you set Find the mean value over to:
Entire input
— The output at each sample time is a scalar that contains the mean value of the MbyNbyP input matrix.Each row
— The output at each sample time consists of an Mby1byP array, where each element contains the mean value of each vector over the second dimension of the input. For an MbyN matrix input, the output at each sample time is an Mby1 column vector.Each column
— The output at each sample time consists of a 1byNbyP array, where each element contains the mean value of each vector over the first dimension of the input. For an MbyN matrix input, the output at each sample time is a 1byN row vector.In this mode, the block treats lengthM unoriented vector inputs as Mby1 column vectors.
Specified dimension
— The output at each sample time depends on the value of the Dimension parameter. If you set the Dimension to1
, the output is the same as when you selectEach column
. If you set the Dimension to2
, the output is the same as when you selectEach row
. If you set the Dimension to3
, the output at each sample time is an MbyN matrix containing the mean value of each vector over the third dimension of the input.
When you select Running mean, the block tracks the mean value of each channel in a time sequence of inputs. In this mode, you must also specify a value for the Input processing parameter.
Elements as channels (sample based)
— The block treats each element of the input as a separate channel. For a threedimensional input signal of size MbyNbyP, the block outputs an MbyNbyP array. Each element y_{ijk} of the output contains the mean value of the element u_{ijk} for all inputs since the last reset.When a reset event occurs, the running mean y_{ijk} in the current frame is reset to the element u_{ijk}.
Columns as channels (frame based)
— The block treats each column of the input as a separate channel. This option does not support an Ndimensional input signal, where N > 2. For a twodimensional input signal of size MbyN, the block outputs an MbyN matrix. Each element y_{ij} of the output contains the mean of the values in the jth column of all inputs since the last reset, up to and including the element u_{ij} of the current input.When a reset event occurs, the running mean for each channel becomes the mean value of all the samples in the current input frame, up to and including the current input sample.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
Complex Number Support: Yes
Parameters
Main Tab
Running mean
— Option to select running mean
off (default)  on
When you select the Running mean parameter, the block tracks the mean value of each channel in a time sequence of inputs.
Find the mean value over
— Dimension over which the block computes the mean value
Each column
(default)  Entire input
 Each row
 Specified dimension
Each column
— The block outputs the mean value over each column.Each row
— The block outputs the mean value over each row.Entire input
— The block outputs the mean value over the entire input.Specified dimension
— The block outputs the mean value over the dimension, specified in the Dimension parameter.
Dependencies
To enable this parameter, clear the Running mean parameter.
Dimension
— Custom dimension
1
(default)  scalar
Specify the dimension (onebased value) of the input signal over which the mean is computed. The value of this parameter must be greater than 0 and less than the number of dimensions in the input signal.
Dependencies
To enable this parameter, set Find the mean value
over to Specified
dimension
.
Input processing
— Method to process the input in running mode
Columns as channels (frame
based)
(default)  Elements as channels (sample
based)
Columns as channels (frame based)
— The block treats each column of the input as a separate channel. This option does not support an Ndimensional input signal, where N > 2. For a twodimensional input signal of size MbyN, the block outputs an MbyN matrix. Each element y_{ij} of the output contains the mean of the values in the jth column of all inputs since the last reset, up to and including the element u_{ij} of the current input.When a reset event occurs, the running mean for each channel becomes the mean value of all the samples in the current input frame, up to and including the current input sample.
Elements as channels (sample based)
— The block treats each element of the input as a separate channel. For a threedimensional input signal of size MbyNbyP, the block outputs an MbyNbyP array. Each element y_{ijk} of the output contains the mean value of the element u_{ijk} for all inputs since the last reset.When a reset event occurs, the running mean y_{ijk} in the current frame is reset to the element u_{ijk}.
VariableSize Inputs
When your inputs are of variable size, and you select the Running mean parameter, then:
If you set the Input processing parameter to
Elements as channels (sample based)
, the state is reset.If you set the Input processing parameter to
Columns as channels (frame based)
, then:When the input size difference is in the number of channels (number of columns), the state is reset.
When the input size difference is in the length of channels (number of rows), there is no reset and the running operation is carried out as usual.
Dependencies
To enable this parameter, select the Running mean parameter.
Reset port
— Reset event
None
(default)  Rising edge
 Falling edge
 Either edge
 Nonzero sample
The block resets the running mean whenever a reset event is detected at the optional Rst port. The reset sample time must be a positive integer multiple of the input sample time.
When a reset event occurs while the Input
processing parameter is set to Elements as
channels (sample based)
, the running mean for each
channel is initialized to the value in the corresponding channel of the
current input. Similarly, when the Input processing
parameter is set to Columns as channels (frame
based)
, the running mean for each channel becomes the
mean value of all the samples in the current input frame, up to and
including the current input sample.
Use this parameter to specify the reset event.
None
— Disables the Rst port.Rising edge
— Triggers a reset operation when the Rst input does one of the following:Rises from a negative value to either a positive value or zero.
Rises from zero to a positive value, where the rise is not a continuation of a rise from a negative value to zero.
Falling edge
— Triggers a reset operation when the Rst input does one of the following:Falls from a positive value to a negative value or zero.
Falls from zero to a negative value, where the fall is not a continuation of a fall from a positive value to zero.
Either edge
— Triggers a reset operation when the Rst input is aRising edge
orFalling edge
.Nonzero sample
— Triggers a reset operation at each sample time, when the Rst input is not zero.
Note
When running simulations in the Simulink multitasking mode, reset signals have a onesample latency. Therefore, when the block detects a reset event, there is a onesample delay at the reset port rate before the block applies the reset. For more information on latency and the Simulink tasking modes, see Excess Algorithmic Delay (Tasking Latency) and TimeBased Scheduling and Code Generation (Simulink Coder).
Dependencies
To enable this parameter, select the Running mean parameter.
Data Types Tab
Note
To use these parameters, the data input must be fixedpoint. For all other inputs, the parameters on the Data Types tab are ignored.
Rounding mode
— Method of rounding operation
Floor
(default)  Ceiling
 Convergent
 Nearest
 Round
 Simplest
 Zero
Specify the rounding mode for fixedpoint operations as one of the following:
Floor
Ceiling
Convergent
Nearest
Round
Simplest
Zero
For more details, see rounding mode.
Saturate on integer overflow
— Method of overflow action
off (default)  on
When you select this parameter, the block saturates the result of its
fixedpoint operation. When you clear this parameter, the block wraps
the result of its fixedpoint operation. For details on
saturate
and wrap
, see overflow
mode for fixedpoint operations.
Accumulator
— Accumulator data type
Inherit: Same as
input
(default)  fixdt([],16,0)
Accumulator specifies the data type of the output of an accumulation operation in the Mean block. See Fixed Point for illustrations depicting the use of the accumulator data type in this block. You can set this parameter to:
Inherit: Same as input
— The block specifies the accumulator data type to be the same as the input data type.fixdt([],16,0)
— The block specifies an autosigned, binarypoint, scaled, fixedpoint data type with a word length of 16 bits and a fraction length of 0.
Alternatively, you can set the Accumulator data type by using the Data Type Assistant. To use the assistant, click the Show data type assistant button.
For more information on the data type assistant, see Specify Data Types Using Data Type Assistant (Simulink).
Output
— Output data type
Inherit: Same as
accumulator
(default)  fixdt([],16,0)
Output specifies the data type of the output of the Mean block. See Fixed Point for illustrations depicting the use of the output data type in this block. You can set it to:
Inherit: Same as accumulator
— The block specifies the output data type to be the same as the accumulator data type.fixdt([],16,0)
— The block specifies an autosigned, binarypoint, scaled, fixedpoint data type with a word length of 16 bits and a fraction length of 0.
Alternatively, you can set the Output data type by using the Data Type Assistant. To use the assistant, click the Show data type assistant button.
For more information on the data type assistant, see Specify Data Types Using Data Type Assistant (Simulink).
Output Minimum
— Minimum value the block can output
[]
(default)  scalar
Specify the minimum value that the block can output. The default value
is []
(unspecified). Simulink uses this value to perform:
Simulation range checking. See Specify Signal Ranges (Simulink).
Automatic scaling of fixedpoint data types.
Output Maximum
— Maximum value the block can output
[]
(default)  scalar
Specify the maximum value that the block can output. The default value
is []
(unspecified). Simulink uses this value to perform:
Simulation range checking. See Specify Signal Ranges (Simulink).
Automatic scaling of fixedpoint data types.
Lock data type settings against changes by the fixedpoint tools
— Prevent fixedpoint tools from overriding data types
off (default)  on
Select this parameter to prevent the fixedpoint tools from overriding the data types you specify on the block.
Model Examples
Block Characteristics
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 

Algorithms
Mean
When you clear the Running mean parameter and specify a
dimension, the block produces results identical to the MATLAB^{®}
mean
function, when it is called as y =
mean(u,D)
.
u
is the data input.D
is the dimension.y
is the mean value.
The mean value along the entire input is identical to calling the
mean
function as y = mean(u(:))
.
The mean of a complex input is computed independently for the real and imaginary components.
Running Mean
When you select the Running mean parameter, and set the
Input processing parameter to Columns as
channels (frame based)
, the block treats each column of the input
as a separate channel. In this example, the block processes a twochannel signal
with a frame size of three under these settings.
The block outputs the mean value over each channel since the last reset. At t = 2, the reset event occurs. The window of data in the second column now contains only 6.
When you select the Running mean parameter, and set the
Input processing parameter to Elements as
channels (sample based)
, the block treats each element of the
input as a separate channel. In this example, the block processes a twochannel
signal with a frame size of three under these settings.
Each y_{ij} element of the output contains the mean value observed in element u_{ij} for all inputs since the last reset. The reset event occurs at t = 2. When a reset event occurs, the running mean, y_{ij}, in the current frame is reset to element u_{ij}.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
FixedPoint Conversion
Design and simulate fixedpoint systems using FixedPoint Designer™.
The following diagram shows the data types used within the Mean block for fixedpoint signals.
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)