Median
Median value of input
 Library:
DSP System Toolbox / Statistics
Description
The Median block computes the median of each row or column of the
input, or along vectors of a specified dimension of the input. It can also compute the
median of the entire input. You can specify the dimension using the Find the
median value over parameter. While computing the median, the block first
sorts the input values. If the number of values is odd, the median is the middle value.
If the number of values is even, the median is the average of the two middle values. To
sort the data, you can specify the Sort algorithm parameter as
either Quick sort
or Insertion
sort
. The block sorts complex inputs according to their
magnitude.
Ports
Input
Port_1
— 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.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
Complex Number Support: Yes
Output
Port_1
— Median value along specified dimension
vector  matrix  ND array
The block computes the median value in each row or column of the
input, or along vectors of a specified dimension of the input. It can
also compute the median of the entire input. Each element in the output
array y
is the median value of the corresponding
column, row, or entire input. The output array y
depends on the setting of the Find the median value
over parameter.
Consider a threedimensional input signal of size MbyNbyP. When you set Find the median value over to:
Entire input
— The output at each sample time is a scalar that contains the median value of the MbyNbyP input matrix.Each row
— The output at each sample time consists of an Mby1byP array, where each element contains the median value of each vector over the second dimension of the input. For an MbyN matrix input, the output is an Mby1 column vector.Each column
— The output at each sample time consists of a 1byNbyP array, where each element contains the median 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 median value of each vector over the third dimension of the input.The data type of the output matches the data type of the input.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
Complex Number Support: Yes
Parameters
Main Tab
Sort algorithm
— Sort method
Quick sort
(default)  Insertion sort
Specify the sorting algorithm as either Quick
sort
or Insertion
sort
.
Find the median value over
— Dimension over which the median is computed
Each column
(default)  Entire input
 Each row
 Specified dimension
Each column
— The block outputs the median value over each column.Each row
— The block outputs the median value over each row.Entire input
— The block outputs the median value over the entire input.Specified dimension
— The block outputs the median value over the dimension specified in the Dimension parameter.
Dimension
— Custom dimension
1
(default)  scalar
Specify the dimension (onebased value) of the input signal over which the block computes the median. The value of this parameter must be greater than 0 and less than or equal to the number of dimensions in the input signal.
Dependencies
To enable this parameter, set Find the median value
over to Specified
dimension
.
Data Types Tab
Note
To use these parameters, the data input must be fixed point. 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. 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.
Product output
— Product output data type
Inherit: Same as
input
(default)  fixdt([],16,0)
Specify the data type of the output of a product operation in the Median block. For more information, see Fixed Point and Multiplication Data Types.
You can set this parameter to:
Inherit: Same as input
— The product output data type is the same as the input data type.fixdt([],16,0)
— The product output data type is 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 Product 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).
Accumulator
— Accumulator data type
Inherit: Same as product
output
(default)  Inherit: Same as input
 fixdt([],16,0)
Specify the data type of the output of an accumulation operation in the Median block. For more details, see Fixed Point.
You can set this parameter to:
Inherit: Same as product output
— The accumulator data type is the same as the product output data type.Inherit: Same as input
— The accumulator data type is the same as the input data type.fixdt([],16,0)
— The accumulator data type is 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)  Inherit: Same as input
 Inherit: Same as product output
 fixdt([],16,0)
Output specifies the data type of the output of the Median block. For more details, see Fixed Point.
You can set this parameter to:
Inherit: Same as accumulator
— The output data type is the same as the accumulator data type.Inherit: Same as input
— The output data type is the same as the input data type.Inherit: Same as product output
— The output data type is the same as the product output data type.fixdt([],16,0)
— The output data type is 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 output value
[]
(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 output value
[]
(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.
Block Characteristics
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 

Algorithms
Median
The median of a set of data is calculated using the following steps:
The values are sorted using the specified sorting algorithm.
If the number of values is odd, the median is the middle value.
If the number of values is even, the median is the average of the two middle values.
The block produces results identical to the MATLAB^{®}
median
function when called as y =
median(u,D)
, where
u
is the data input.D
is the dimension.y
is the median value.
When the block calculates the median value along the entire input, the result is
identical to calling the median
function as y =
median(u(:))
.
When the input is complex, the block sorts the data according to the magnitude of each value. The magnitude in this case is defined as the sum of the squares of the real and imaginary components of the complex input.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Generated code relies on memcpy
or
memset
functions (string.h
) under certain
conditions.
FixedPoint Conversion
Design and simulate fixedpoint systems using FixedPoint Designer™.
For fixedpoint inputs, you can specify the Accumulator, Product output, and Output data types in the block dialog box. Not all of these fixedpoint parameters are applicable to all types of fixedpoint inputs. The table shows when each kind of data type and scaling is used.
M is the length of the sorted data along the specified
dimension. X
indicates that the particular data type is
applicable.
Output data type  Accumulator data type  Product output data type  

Even M  X  X  Not Applicable 
Odd M  X  Not Applicable  Not Applicable 
Odd M and complex  X  X  X 
Even M and complex  X  X  X 
When M is even, the Accumulator and Output data types and scalings are used for fixedpoint signals. While calculating the average of the two central rows of the input matrix, the result of the sum is stored in the Accumulator data type and scaling. The total result of the average, which is the median of the data, is stored in the Output data type and scaling.
When the fixedpoint inputs are complex, both the Accumulator and the Product output data types are used in addition to the Output data type. Before sorting the data, the block computes the sum of the squares of the real and imaginary components of the complex input. The results of the squares are stored in the Product output data type and scaling. The result of the sum of the squares is stored in the Accumulator data type and scaling.
For fixedpoint inputs that are both complex and have even M, the Accumulator data type also stores the sum of the two central rows of the input matrix. The average of the two central rows, which is the median of the data, is stored in the Output data type.
See Also
Functions
Objects
Blocks
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
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)