| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
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.
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 = -a-b+c, the Sum block reorders the inputs so that output = c-a-b. 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 fixed-point 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 output = -a-b+c, you can use the Unary Minus block in the Math Operations library. |
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 (–Input1 + Input2) to (Input2 – Input1). |
| 2 | Initializes the accumulator by using the first + input port: Accumulator = int8(-1) = -1 |
| 3 | Continues to accumulate values: Accumulator = Accumulator – int8(-128) = 127 |
| 4 | Calculates the block output: Output = int8(127) = 127 |
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: Accumulator = int8(-(-128)) = 127 Because saturation is on, the initial value of the accumulator saturates at 127 and does not wrap. |
| 2 | Continues to accumulate values: Accumulator = Accumulator + int8(-1) = 126 |
| 3 | Calculates the block output: Output = int8(126) = 126 |
The Sum block accepts real or complex signals of any numeric data type supported by Simulink software, including fixed-point data types. The inputs may be of different data types unless you select the Require all inputs to have the same data type parameter.
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.
See Specifying Block Output Data Types for more information.
See Block-Specific Parameters for the command-line information.
Designate the icon shape of the block.
Default: round
Designate the icon shape of the block as rectangular.
Designate the icon shape of the block as round.
See Block-Specific Parameters for the command-line 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 Block-Specific Parameters for the command-line information.
Select dimension over which to perform the sum over operation.
Default: All dimensions
Sum all input elements, yielding a scalar.
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 Block-Specific Parameters for the command-line 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 2-by-3 matrix U.
Setting Dimension to 1 results in the output Y being computed as:
![]()
Setting Dimension to 2 results in the output Y being computed as:
![]()
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 Block-Specific Parameters for the command-line information.
Enter the discrete interval between sample time hits or specify another appropriate sample time such as continuous or inherited.
Default: -1
By default, the block inherits its sample time based upon the context of the block within the model. To set a different sample time, enter a valid sample time based upon the table in Types of Sample Time.
See also How to Specify the Sample Time in the online documentation for more information.
See Block-Specific Parameters for the command-line information.
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 Block-Specific Parameters for the command-line information.
Select to lock data type settings of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor.
Default: Off
Locks all data type settings for this block.
Allows the Fixed-Point Tool and the Fixed-Point Advisor to change data type settings for this block.
See Block-Specific Parameters for the command-line information.
Select the rounding mode for fixed-point operations.
Default: Floor
Round both positive and negative numbers toward positive infinity.
Round number to the nearest representable value. If a tie occurs, round to the nearest even stored value.
Round both positive and negative numbers toward negative infinity.
Round number to the nearest representable value. If a tie occurs, round toward positive infinity.
Round number to the nearest representable value. If a tie occurs, round positive numbers toward positive infinity and round negative numbers toward negative infinity.
This option provides for an optimization of the rounding code for several blocks.
Round number toward zero.
See Block-Specific Parameters for the command-line information.
For more information, see Rounding in the Simulink Fixed Point User's Guide.
Specify whether overflows saturate.
Default: Off
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 which case, no saturation code is necessary.
See Block-Specific Parameters for the command-line information.
Specify the accumulator data type.
Default: Inherit: Inherit via internal rule
Use internal rule to determine accumulator data type.
Use data type of first input signal.
Accumulator data type is double.
Accumulator data type is single.
Accumulator data type is int8.
Accumulator data type is uint8.
Accumulator data type is int16.
Accumulator data type is uint16.
Accumulator data type is int32.
Accumulator data type is uint32.
Accumulator data type is fixed point fixdt(1,16,0).
Accumulator data type is fixed point fixdt(1,16,2^0,0).
The name of a data type object, for example Simulink.NumericType
See Block-Specific Parameters for the command-line information.
See Using the Data Type Assistant in the Simulink User's Guide for more information.
Select the category of accumulator data to specify
Default: Inherit
Inheritance rules for data types. Selecting Inherit enables a second menu/text box to the right. Below are the possible values, which can vary by block:
Inherit via internal rule
Same as first input
Built-in data types. Selecting Built in enables a second menu/text box to the right. Below are the possible values, which can vary by block:
double
single
int8
uint8
int16
uint16
int32
uint32
Fixed-point data types.
Enumerated data types. This option is available on some blocks.
Expressions that evaluate to data types. Selecting Expression enables a second menu/text to the right. Below are the possible values, which can vary by block:
<data type expression>
Clicking the Show data type assistant button for the accumulator data type enables this parameter.
See Block-Specific Parameters for the command-line information.
See Using the Data Type Assistant in the Simulink User's Guide.
Specify whether you want the fixed-point data to be signed or unsigned.
Default: Signed
Specify the fixed-point data to be signed.
Specify the fixed-point data to be unsigned.
Selecting Mode > Fixed point for the accumulator data type enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide 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 Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.
Default: Best precision or Binary point
Specify binary point location.
Enter slope and bias.
Specify best-precision values. This option appears for some blocks.
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 Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify fraction length for fixed-point 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 Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify slope for the fixed-point data type.
Default: 2^0
Specify any positive real number.
Selecting Scaling > Slope and bias for the accumulator data type enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify bias for the fixed-point data type.
Default: 0
Specify any real number.
Selecting Scaling > Slope and bias for the accumulator data type enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify the minimum value that the block should output.
Default: []
The default value, [], is equivalent to -Inf.
Simulink software uses this value to perform:
Parameter range checking (see Checking Parameter Values) for some blocks
Simulation range checking (see Checking Signal Ranges)
Automatic scaling of fixed-point data types
This number must be a double scalar value.
See Block-Specific Parameters for the command-line information.
Specify the maximum value that the block should output.
Default: []
The default value, [], is equivalent to Inf.
Simulink software uses this value to perform:
Parameter range checking (see Checking Parameter Values) for some blocks
Simulation range checking (see Checking Signal Ranges)
Automatic scaling of fixed-point data types
This number must be a double scalar value.
See Block-Specific Parameters for the command-line information.
Specify the output data type.
Default: Inherit: Inherit via internal rule (Discrete-Time Integrator, Gain, Product, Sum, Switch block), Inherit: Inherit from 'Constant value' (Constant block), Inherit: Inherit via back propagation (Data Type Conversion block), Inherit: Same as input (Saturation block)
This option appears for some blocks. Simulink software chooses a combination of output scaling and data type that requires the smallest amount of memory consistent with accommodating the calculated output range and maintaining the output precision of the block and with the word size of the targeted hardware implementation specified for the model. If the Device type parameter on the Hardware Implementation configuration parameters pane is set to ASIC/FPGA, Simulink software chooses the output data type without regard to hardware constraints. Otherwise, Simulink software chooses the smallest available hardware data type capable of meeting the range and precision constraints. For example, if the block multiplies an input of type int8 by a gain of int16 and ASIC/FPGA is specified as the targeted hardware type, the output data type is sfix24. If Unspecified (assume 32-bit Generic), i.e., a generic 32-bit microprocessor, is specified as the target hardware, the output data type is int32. If none of the word lengths provided by the target microprocessor can accommodate the output range, Simulink software displays an error message in the Simulation Diagnostics Viewer.
Use data type of Constant value parameter. This option appears for some blocks.
Use data type of the driving block.
Use data type of sole input signal. This option appears for some blocks.
Use data type of first input signal. This option appears for some blocks.
Output data type is the same as accumulator data type. This option appears for some blocks.
Output data type is double.
Output data type is single.
Output data type is int8.
Output data type is uint8.
Output data type is int16.
Output data type is uint16.
Output data type is int32.
Output data type is unt32.
Output data type is fixed point fixdt(1,16,0).
Output data type is fixed point fixdt(1,16,2^0,0).
Use an enumerated data type, for example, Enum: BasicColors. This option appears for some blocks.
Use a data type object, for example, Simulink.NumericType.
See Block-Specific Parameters for the command-line information.
See Specifying Block Output Data Types in the Simulink User's Guide for more information.
Select the category of data to specify.
Default: Inherit (Constant, Data Type Conversion, Discrete Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch), Built in (Logical Operator, Relational Operator)
Inheritance rules for data types. Selecting Inherit enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
Inherit from 'Constant value' (Constant block default)
Inherit via internal rule (Discrete-Time Integrator, Gain, Product, Sum, Switch block default)
Inherit via back propogation (Data Type Conversion block default)
auto (Inport, Outport block default)
Logical (see Configuration Parameters: Optimization)
Same as first input
Same as input (Saturation block default)
Same as accumulator
Built-in data types. Selecting Built in enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
double (Constant, Data Type Conversion, Discrete-Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch block default)
single
int8
uint8
int16
uint16
int32
uint32
boolean (Logical Operator, Relational Operator block default)
Fixed-point data types.
Enumerated data types. This option is available on some blocks. Selecting Enumerated enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
<class name>
Expressions that evaluate to data types. Selecting Expression enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
<data type expression>
Clicking the Show data type assistant button enables this parameter.
See Block-Specific Parameters for the command-line information.
See Using the Data Type Assistant in the Simulink User's Guide.
Specify whether you want the fixed-point data as signed or unsigned.
Default: Signed
Selecting Mode > Fixed point enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify the bit size of the word that holds 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 enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.
Default: Best precision (Constant), Binary point (Data Type Conversion, Discrete-Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch), Integer (Logical Operator, Relational Operator)
Specify binary point location.
Enter slope and bias.
Specify best-precision values. This option appears for some blocks.
Specify integer. This setting has the same result as specifying a binary point location and setting fraction length to 0. This option appears for some blocks.
Selecting Mode > Fixed point enables this parameter.
Selecting Binary point enables:
Fraction length
Calculate Best-Precision Scaling
Selecting Slope and bias enables:
Slope
Bias
Calculate Best-Precision Scaling
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify fraction length for fixed-point data type.
Default: 0
Binary points can be positive or negative integers.
Selecting Scaling > Binary point enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify slope for the fixed-point data type.
Default: 2^0
Specify any positive real number.
Selecting Scaling > Slope and bias enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify bias for the fixed-point data type.
Default: 0
Specify any real number.
Selecting Scaling > Slope and bias enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Direct Feedthrough | Yes |
Sample Time | Specified in the Sample time parameter |
Scalar Expansion | Yes |
States | 0 |
Dimensionalized | Yes |
Multidimensionalized | Yes, only along the specified dimension |
Zero Crossing | No |
![]() | Subsystem, Atomic Subsystem, Nonvirtual Subsystem, CodeReuse Subsystem | Switch | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |