Add or subtract inputs
Math Operations
The Sum block performs addition or subtraction on its inputs. This block can add or subtract scalar, vector, or matrix inputs. It can also collapse the elements of a signal.
You specify the operations of the block with the List
of signs parameter. Plus (+
), minus (
), and spacer (
)
characters indicate the operations to be performed on the inputs:
If there are two or more inputs, then the number of +
and 
characters
must equal the number of inputs. For example, "++
"
requires three inputs and configures the block to subtract the second
(middle) input from the first (top) input, and then add the third
(bottom) input.
All nonscalar inputs must have the same dimensions. Scalar inputs will be expanded to have the same dimensions as the other inputs.
A spacer character creates extra space between ports on the block's icon.
For a round Sum block, the first input port is the port closest to the 12 o'clock position going in a counterclockwise direction around the block. Similarly, other input ports appear in counterclockwise order around the block.
If only addition of all inputs is required, then a
numeric parameter value equal to the number of inputs can be supplied
instead of "+
" characters.
If only one input port is required, a single "+
"
or "
" collapses the element via
the specified operation.
The Sum block first converts the input data type(s) to its accumulator data type, then performs the specified operations. The block converts the result to its output data type using the specified rounding and overflow modes.
Output calculation for the Sum block depends on the number of block inputs and the sign of input ports:
If the Sum block has...  And...  The formula for output calculation is...  Where... 

One input port  The input port sign is +  y = e[0] + e[1] + e[2] ... + e[m] 

The input port sign is –  y = 0.0 – e[0] – e[1] – e[2] ... – e[m]  
Two or more input ports  All input port signs are –  y = 0.0 – u[0] – u[1] – u[2] ... – u[n] 

The k^{th} input port is the first port where the sign is +  y = u[k] – u[0] – u[1] – u[2] – u[k–1] (+/–) u[k+1] ... (+/–) u[n] 
The Sum block accepts real or complex signals of the following data types:
Floating point
Builtin integer
Fixed point
Boolean
The inputs can be of different data types, unless you select the Require all inputs to have the same data type parameter. For more information, see Data Types Supported by Simulink in the Simulink^{®} documentation.
The Main pane of the Sum block dialog box appears as follows:
The Signal Attributes pane of the Sum block dialog box appears as follows:
Display the Data Type Assistant.
The Data Type Assistant helps you set the Output data type parameter.
For more information, see Control Signal Data Types.
Designate the icon shape of the block.
Default: round
rectangular
Designate the icon shape of the block as rectangular.
round
Designate the icon shape of the block as round.
See BlockSpecific Parameters for the commandline information.
Enter plus (+
) and minus (
)
characters.
Default: ++
Addition is the default operation, so if you only want to add the inputs, enter the number of input ports.
For a single vector input, "+
"
or "
" will collapse the vector using
the specified operation.
Enter as many plus (+
) and minus
(
) characters as there are inputs.
You can manipulate the positions of the input ports on the block
by inserting spacers (
) between the signs in the List of signs parameter. For example, "++
"
creates an extra space between the second and third input ports.
Entering only one element enables the Sum over parameter.
See BlockSpecific Parameters for the commandline information.
Select dimension over which to perform the sum over operation.
Default: All dimensions
All dimensions
Sum all input elements, yielding a scalar.
Specified dimension
Display the Dimension parameter, where you specify the dimension over which to perform the operation.
Selecting Specified dimension
enables
the Dimension parameter.
List of signs (when it has only one element) enables this parameter.
See BlockSpecific Parameters for the commandline information.
Specify the dimension over which to perform the operation.
Default: 1
The block follows the same summation rules as the MATLAB^{®} sum
function.
Suppose that you have a 2by3 matrix U.
Setting Dimension to 1
results
in the output Y being computed as:
$$Y={\displaystyle {\sum}_{i=1}^{2}U(i,j)}$$
Setting Dimension to 2
results
in the output Y being computed as:
$$Y={\displaystyle {\sum}_{j=1}^{3}U(i,j)}$$
If the specified dimension is greater than the dimension of the input, an error message appears.
Setting Sum over to Specified
dimension
enables this parameter.
See BlockSpecific Parameters for the commandline information.
Note:
This parameter is not visible in the block dialog box unless
it is explicitly set to a value other than 
Require that all inputs have the same data type.
Default: Off
Require that all inputs have the same data type.
Do not require that all inputs have the same data type.
See BlockSpecific Parameters for the commandline information.
Select to lock data type settings of this block against changes by the FixedPoint Tool and the FixedPoint Advisor.
Default: Off
Locks all data type settings for this block.
Allows the FixedPoint Tool and the FixedPoint Advisor to change data type settings for this block.
See BlockSpecific Parameters for the commandline information.
Specify the rounding mode for fixedpoint operations.
Default: Floor
Ceiling
Rounds both positive and negative numbers toward positive infinity.
Equivalent to the MATLAB ceil
function.
Convergent
Rounds number to the nearest representable value. If a tie occurs,
rounds to the nearest even integer. Equivalent to the FixedPoint Designer™ convergent
function.
Floor
Rounds both positive and negative numbers toward negative infinity.
Equivalent to the MATLAB floor
function.
Nearest
Rounds number to the nearest representable value. If a tie occurs,
rounds toward positive infinity. Equivalent to the FixedPoint Designer nearest
function.
Round
Rounds number to the nearest representable value. If a tie occurs,
rounds positive numbers toward positive infinity and rounds negative
numbers toward negative infinity. Equivalent to the FixedPoint Designer round
function.
Simplest
Automatically chooses between round toward floor and round toward zero to generate rounding code that is as efficient as possible.
Zero
Rounds number toward zero. Equivalent to the MATLAB fix
function.
Parameter: RndMeth 
Type: string 
Value: 'Ceiling'  'Convergent'  'Floor'  'Nearest'  'Round'  'Simplest'  'Zero' 
Default: 'Floor' 
For more information, see Rounding in the FixedPoint Designer documentation.
Specify whether overflows saturate.
Default: Off
Overflows saturate to either the minimum or maximum value that the data type can represent.
For example, an overflow associated with a signed 8bit integer can saturate to 128 or 127.
Overflows wrap to the appropriate value that the data type can represent.
For example, the number 130 does not fit in a signed 8bit integer and wraps to 126.
Consider selecting this check box when your model has a possible overflow and you want explicit saturation protection in the generated code.
Consider clearing this check box when you want to optimize efficiency of your generated code.
Clearing this check box also helps you to avoid overspecifying how a block handles outofrange signals. For more information, see Checking for Signal Range Errors.
When you select this check box, saturation applies to every internal operation on the block, not just the output or result.
In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.
Parameter: SaturateOnIntegerOverflow 
Type: string 
Value: 'off'  'on' 
Default: 'off' 
Specify the accumulator data type.
Default: Inherit:
Inherit via internal rule
Inherit: Inherit via internal rule
Use internal rule to determine accumulator data type.
Inherit: Same as first input
Use data type of first input signal.
double
Accumulator data type is double
.
single
Accumulator data type is single
.
int8
Accumulator data type is int8
.
uint8
Accumulator data type is uint8
.
int16
Accumulator data type is int16
.
uint16
Accumulator data type is uint16
.
int32
Accumulator data type is int32
.
uint32
Accumulator data type is uint32
.
fixdt(1,16,0)
Accumulator data type is fixed point fixdt(1,16,0)
.
fixdt(1,16,2^0,0)
Accumulator data type is fixed point fixdt(1,16,2^0,0)
.
<data type expression>
The name of a data type object, for example Simulink.NumericType
See BlockSpecific Parameters for the commandline information.
For more information, see Specify Data Types Using Data Type Assistant.
Select the category of accumulator data to specify
Default: Inherit
Inherit
Specifies inheritance rules for data types. Selecting Inherit
enables
a list of possible values:
Inherit via internal rule
(default)
Same as first input
Built in
Specifies builtin data types. Selecting Built
in
enables a list of possible values:
double
(default)
single
int8
uint8
int16
uint16
int32
uint32
Fixed point
Specifies fixedpoint data types.
Expression
Specifies expressions that evaluate to data types. Selecting Expression
enables
you to enter an expression.
Clicking the Show data type assistant button for the accumulator data type enables this parameter.
See BlockSpecific Parameters for the commandline information.
See Specify Data Types Using Data Type Assistant.
Specify data type override mode for this signal.
Default: Inherit
Inherit
Inherits the data type override setting from its context, that
is, from the block, Simulink.Signal
object or Stateflow^{®} chart
in Simulink that is using the signal.
Off
Ignores the data type override setting of its context and uses the fixedpoint data type specified for the signal.
The ability to turn off data type override for an individual data type provides greater control over the data types in your model when you apply data type override. For example, you can use this option to ensure that data types meet the requirements of downstream blocks regardless of the data type override setting.
This parameter appears only when the Mode is Built
in
or Fixed point
.
Specify whether you want the fixedpoint data to be signed or unsigned.
Default: Signed
Signed
Specify the fixedpoint data to be signed.
Unsigned
Specify the fixedpoint data to be unsigned.
Selecting Mode > Fixed
point
for the accumulator data type enables this parameter.
See BlockSpecific Parameters for the commandline information.
See Specifying a FixedPoint Data Type for more information.
Specify the bit size of the word that will hold the quantized integer.
Default: 16
Minimum: 0
Maximum: 32
Large word sizes represent large values with greater precision than small word sizes.
Selecting Mode > Fixed
point
for the accumulator data type enables this parameter.
See BlockSpecific Parameters for the commandline information.
See Specifying a FixedPoint Data Type for more information.
Specify the method for scaling your fixedpoint data to avoid overflow conditions and minimize quantization errors.
Default: Binary
point
Binary point
Specify binary point location.
Slope and bias
Enter slope and bias.
Selecting Mode > Fixed
point
for the accumulator data type enables this parameter.
Selecting Binary point
enables:
Fraction length
Selecting Slope and bias
enables:
Slope
Bias
See BlockSpecific Parameters for the commandline information.
See Specifying a FixedPoint Data Type for more information.
Specify fraction length for fixedpoint data type.
Default: 0
Binary points can be positive or negative integers.
Selecting Scaling > Binary
point
for the accumulator data type enables this parameter.
See BlockSpecific Parameters for the commandline information.
See Specifying a FixedPoint Data Type for more information.
Specify slope for the fixedpoint data type.
Default: 2^0
Specify any positive real number.
Selecting Scaling > Slope
and bias
for the accumulator data type enables this
parameter.
See BlockSpecific Parameters for the commandline information.
See Specifying a FixedPoint Data Type for more information.
Specify bias for the fixedpoint data type.
Default: 0
Specify any real number.
Selecting Scaling > Slope
and bias
for the accumulator data type enables this
parameter.
See BlockSpecific Parameters for the commandline information.
See Specifying a FixedPoint Data Type for more information.
Lower value of the output range that Simulink checks.
Default: []
(unspecified)
Specify this number as a finite, real, double, scalar value.
Simulink uses the minimum to perform:
Parameter range checking (see Control Block Parameter Value Ranges) for some blocks
Simulation range checking (see Signal Ranges and Enabling Simulation Range Checking)
Automatic scaling of fixedpoint data types
Note: Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead. 
Parameter: OutMin 
Type: string 
Value: '[ ]' 
Default: '[ ]' 
Upper value of the output range that Simulink checks.
Default: []
(unspecified)
Specify this number as a finite, real, double, scalar value.
Simulink uses the maximum value to perform:
Parameter range checking (see Control Block Parameter Value Ranges) for some blocks
Simulation range checking (see Signal Ranges and Enabling Simulation Range Checking)
Automatic scaling of fixedpoint data types
Note: Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead. 
Parameter: OutMax 
Type: string 
Value: '[ ]' 
Default: '[ ]' 
Specify the output data type.
Default: Inherit:
Inherit via internal rule
Inherit: Inherit via internal rule
Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware. If you change the embedded target settings, the data type selected by the internal rule might change. It is not always possible for the software to optimize code efficiency and numerical accuracy at the same time. If the internal rule doesn't meet your specific needs for numerical accuracy or performance, use one of the following options:
Specify the output data type explicitly.
Use the simple choice of Inherit: Same
as first input
.
Explicitly specify a default data type such as fixdt(1,32,16)
and
then use the FixedPoint Tool to propose data types for your model.
For more information, see fxptdlg
.
To specify your own inheritance rule, use Inherit:
Inherit via back propagation
and then use a Data Type Propagation block. Examples
of how to use this block are available in the Signal Attributes library Data
Type Propagation Examples block.
Note:
The accumulator internal rule favors greater numerical accuracy,
possibly at the cost of less efficient generated code. To get the
same accuracy for the output, set the output data type to 
Inherit: Inherit via back propagation
Use data type of the driving block.
Inherit: Same as first input
Use data type of first input signal.
Inherit: Same as accumulator
Output data type is the same as accumulator data type.
double
Output data type is double
.
single
Output data type is single
.
int8
Output data type is int8
.
uint8
Output data type is uint8
.
int16
Output data type is int16
.
uint16
Output data type is uint16
.
int32
Output data type is int32
.
uint32
Output data type is uint32
.
fixdt(1,16,0)
Output data type is fixed point fixdt(1,16,0)
.
fixdt(1,16,2^0,0)
Output data type is fixed point fixdt(1,16,2^0,0)
.
<data type expression>
Use a data type object, for example, Simulink.NumericType
.
See BlockSpecific Parameters for the commandline information.
For more information, see Control Signal Data Types.
Select the category of data to specify.
Default: Inherit
Inherit
Inheritance rules for data types. Selecting Inherit
enables
a second menu/text box to the right. Select one of the following choices:
Inherit via internal rule
(default)
Inherit via back propagation
Same as first input
Same as accumulator
Built in
Builtin data types. Selecting Built in
enables
a second menu/text box to the right. Select one of the following choices:
double
(default)
single
int8
uint8
int16
uint16
int32
uint32
Fixed point
Fixedpoint data types.
Expression
Expressions that evaluate to data types. Selecting Expression
enables
a second menu/text box to the right, where you can enter the expression.
Clicking the Show data type assistant button enables this parameter.
See BlockSpecific Parameters for the commandline information.
See Specify Data Types Using Data Type Assistant.
Specify whether you want the fixedpoint data as signed or unsigned.
Default: Signed
Signed
Specify the fixedpoint data as signed.
Unsigned
Specify the fixedpoint data as unsigned.
Selecting Mode > Fixed
point
enables this parameter.
For more information, see Specifying a FixedPoint Data Type.
Specify the bit size of the word that holds the quantized integer.
Default: 16
Minimum: 0
Maximum: 32
Selecting Mode > Fixed
point
enables this parameter.
For more information, see Specifying a FixedPoint Data Type.
Specify the method for scaling your fixedpoint data to avoid overflow conditions and minimize quantization errors.
Default: Binary
point
Binary point
Specify binary point location.
Slope and bias
Enter slope and bias.
Selecting Mode > Fixed
point
enables this parameter.
Selecting Binary point
enables:
Fraction length
Calculate BestPrecision Scaling
Selecting Slope and bias
enables:
Slope
Bias
Calculate BestPrecision Scaling
See BlockSpecific Parameters for the commandline information.
See Specifying a FixedPoint Data Type.
Specify fraction length for fixedpoint data type.
Default: 0
Binary points can be positive or negative integers.
Selecting Scaling > Binary
point
enables this parameter.
For more information, see Specifying a FixedPoint Data Type.
Specify slope for the fixedpoint data type.
Default: 2^0
Specify any positive real number.
Selecting Scaling > Slope
and bias
enables this parameter.
For more information, see Specifying a FixedPoint Data Type.
Specify bias for the fixedpoint data type.
Default: 0
Specify any real number.
Selecting Scaling > Slope
and bias
enables this parameter.
For more information, see Specifying a FixedPoint Data Type.
If you use 
on the first input port, the
Sum block reorders the inputs so that, if possible, the first input
uses a +
operation. For example, in the expression output
= ab+c
, the Sum block reorders the inputs so that output
= cab
. To initialize the accumulator, the Sum block uses
the first +
input port.
The block avoids performing a unary minus operation on the first
operand a
because doing so can change the value
of a
for fixedpoint data types. In that case,
the output value differs from the result of accumulating the values
for a
, b
, and c
.
Tip
To explicitly specify a unary minus operation for 
Suppose that you have the following model:
The following block parameters apply:
Both Constant blocks, Input1
and Input
2
, use int8
for the Output
data type.
The Sum block uses int8
for
both Accumulator data type and Output
data type.
The Sum block has Saturate on integer overflow turned on
.
The Sum block reorders the inputs so that the following operations occur and you get the ideal result of 127.
Step  Block Operation 

1  Reorders inputs from 
2  Initializes the accumulator by using the first

3  Continues to accumulate values:

4  Calculates the block output:

If the Sum block does not reorder the inputs, the following operations occur instead and you get the nonideal result of 126.
Step  Block Operation 

1  Initializes the accumulator by using the first input port:
Because saturation is on, the initial value of the accumulator saturates at 127 and does not wrap. 
2  Continues to accumulate values:

3  Calculates the block output:

Data Types  Double  Single  Boolean  Base Integer  FixedPoint 
Sample Time  Inherited from driving block 
Direct Feedthrough  Yes 
Multidimensional Signals  Yes 
VariableSize Signals  Yes 
ZeroCrossing Detection  No 
Code Generation  Yes 