| Contents | Index |
Math Operations
The Gain block multiplies the input by a constant value (gain). The input and the gain can each be a scalar, vector, or matrix.
You specify the value of the gain in the Gain parameter. The Multiplication parameter lets you specify element-wise or matrix multiplication. For matrix multiplication, this parameter also lets you indicate the order of the multiplicands.
The gain is converted from doubles to the data specified in the block mask offline using round-to-nearest and saturation. The input and gain are then multiplied, and the result is converted to the output data type using the specified rounding and overflow modes.
The Gain block accepts a real or complex scalar, vector, or matrix of any numeric data type that Simulink supports. The Gain block supports fixed-point data types. If the input of the Gain block is real and the gain is complex, the output is complex.
For more information, see Data Types Supported by Simulink in the Simulink documentation.
The Main pane of the Gain block dialog box appears as follows:

The Signal Attributes pane of the Gain block dialog box appears as follows:

The Parameter Attributes pane of the Gain block dialog box appears as follows:

Specify the value by which to multiply the input.
| Default: 1 |
| Minimum: value of Parameter minimum parameter |
| Maximum: value of Parameter maximum parameter |
The gain can be a scalar, vector, or matrix.
See Block-Specific Parameters for the command-line information.
Specify the multiplication mode.
Default: Element-wise(K.*u)
Each element of the input is multiplied by each element of the gain. The block performs expansions, if necessary, so that the input and gain have the same dimensions.
The input and gain are matrix multiplied with the input as the second operand.
The input and gain are matrix multiplied with the input as the first operand.
The input and gain are matrix multiplied with the input as the second operand. This mode is identical to Matrix(K*u), except for how dimensions are determined.
Suppose that K is an m-by-n matrix. Matrix(K*u)(u vector) sets the input to a vector of length n and the output to a vector of length m. In contrast, Matrix(K*u) uses propagation to determine dimensions for the input and output. For an m-by-n gain matrix, the input can propagate to an n-by-q matrix, and the output becomes an m-by-q matrix.
See Block-Specific Parameters for the command-line information.
Specify the time interval between samples.
Default: -1
To inherit the sample time, set this parameter to -1.
See How to Specify the Sample Time in the online documentation for more information.
See Block-Specific Parameters for the command-line information.
Specify the minimum value that the block should output.
Default: [] (unspecified)
This number must be a finite real double scalar value.
Note If you specify a bus object as the data type for this block, do not set the minimum value for bus data on the block. Simulink ignores this setting. Instead, set the minimum values for bus elements of the bus object specified as the data type. For information on the Minimum property of a bus element, see Simulink.BusElement. |
Simulink uses the minimum to perform:
Parameter range checking (see Checking Parameter Values) for some blocks
Simulation range checking (see Signal Ranges)
Automatic scaling of fixed-point data types
See Block-Specific Parameters for the command-line information.
Specify the maximum value that the block should output.
Default: [] (unspecified)
This number must be a finite real double scalar value.
Note If you specify a bus object as the data type for this block, do not set the maximum value for bus data on the block. Simulink ignores this setting. Instead, set the maximum values for bus elements of the bus object specified as the data type. For information on the Maximum property of a bus element, see Simulink.BusElement. |
Simulink uses the maximum value to perform:
Parameter range checking (see Checking Parameter Values) for some blocks
Simulation range checking (see Signal Ranges)
Automatic scaling of fixed-point data types
See Block-Specific Parameters for the command-line information.
Specify the output data type.
Default: Inherit: Inherit via internal rule
Simulink 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 the driving block.
Use data type of input signal.
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 uint32.
Output data type is fixed point fixdt(1,16,0).
Output data type is fixed point fixdt(1,16,2^0,0).
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
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 input
Built-in 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 data types.
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 Block-Specific Parameters for the command-line information.
See Using the Data Type Assistant in the Simulink User's Guide.
Specify data type override mode for this signal.
Default: 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.
Ignores the data type override setting of its context and uses the fixed-point 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 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
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: Binary point
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.
Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor.
Default: Off
Locks the output data type setting for this block.
Allows the Fixed-Point Tool and the Fixed-Point Advisor to change the output data type setting for this block.
See Block-Specific Parameters for the command-line information.
For more information, see Fixed-Point Tool and Fixed-Point Advisor in the Simulink Fixed Point documentation.
Specify the rounding mode for fixed-point operations.
Default: Floor
Rounds both positive and negative numbers toward positive infinity. Equivalent to the MATLAB ceil function.
Rounds number to the nearest representable value. If a tie occurs, rounds to the nearest even integer. Equivalent to the Fixed-Point Toolbox convergent function.
Rounds both positive and negative numbers toward negative infinity. Equivalent to the MATLAB floor function.
Rounds number to the nearest representable value. If a tie occurs, rounds toward positive infinity. Equivalent to the Fixed-Point Toolbox nearest function.
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 Fixed-Point Toolbox round function.
Automatically chooses between round toward floor and round toward zero to generate rounding code that is as efficient as possible.
Rounds number toward zero. Equivalent to the MATLAB fix function.
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
Overflows saturate to either the minimum or maximum value that the data type can represent.
For example, an overflow associated with a signed 8-bit integer can saturate to -128 or 127.
Overflows wrap to the appropriate value that is representable by the data type.
For example, the number 130 does not fit in a signed 8-bit integer and wraps to -126.
Consider selecting this check box when your model has 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 avoid overspecifying how a block handles out-of-range 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.
See Block-Specific Parameters for the command-line information.
Specify the minimum value of the gain.
| Default: [] |
The default value is [] (unspecified). Simulink software uses this value to perform:
Parameter range checking (see Checking Parameter Values)
Automatic scaling of fixed-point data types
See Block-Specific Parameters for the command-line information.
Specify the maximum value of the gain.
| Default: [] |
The default value is [] (unspecified). Simulink software uses this value to perform:
Parameter range checking (see Checking Parameter Values)
Automatic scaling of fixed-point data types
See Block-Specific Parameters for the command-line information.
Specify the data type of the Gain parameter.
Default: Inherit: Inherit via internal rule
Use an internal rule to inherit the data type.
Use data type of sole input signal.
Use data type of the Gain value. For example:
| If you set Gain to... | The parameter data type inherits... |
|---|---|
| 2 | double |
| single(2) | single |
| int8(2) | int8 |
Data type is double.
Data type is single.
Data type is int8.
Data type is uint8.
Data type is int16.
Data type is uint16.
Data type is int32.
Data type is uint32.
Data type is fixdt(1,16).
Data type is fixdt(1,16,0).
Data type is fixdt(1,16,2^0,0).
Use a data type object, for example, Simulink.NumericType.
See Block-Specific Parameters for the command-line information.
Select the category of data to specify.
Default: 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)
Same as input
Inherit from 'Gain'
Built-in 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 data types.
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 Block-Specific Parameters for the command-line information.
See Using the Data Type Assistant in the Simulink User's Guide.
Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.
Default: Best precision
Specify binary point location.
Enter slope and bias.
Specify best-precision values.
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.
The following Simulink demos show how to use the Gain block:
Direct Feedthrough | Yes |
Sample Time | Specified in the Sample time parameter |
Scalar Expansion | Yes, of input and Gain parameter for Element-wise(K.*u) multiplication |
Dimensionalized | Yes |
Multidimensionalized | Yes, only if the Multiplication parameter specifies Element-wise(K.*u) |
Zero-Crossing Detection | No |

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