Divide
Divide one input by another
- Library:
Simulink / Math Operations
Description
TheDivideblock outputs the result of dividing its first input by its second. The inputs can be scalars, a scalar and a nonscalar, or two nonscalars that have the same dimensions. TheDivideblock is functionally aProductblock that has two block parameter values preset:
Multiplication —
Element-wise(.*)
Number of Inputs —
*/
Setting nondefault values for either of those parameters can change aDivideblock to be functionally equivalent to aProductblock or aProduct of Elementsblock.
Ports
Input
X
— Input signal to multiply
scalar | vector | matrix | N-D array
Input signal to be multiplied with other inputs.
Dependencies
To enable one or moreXports, specify one or more*
characters for theNumber of inputsparameter.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
|Boolean
|fixed point
÷
— Input signal to divide or invert
scalar | vector | matrix | N-D array
Input signal for division or inversion operations.
Dependencies
To enable one or more÷ports, specify one or more/
characters for theNumber of inputsparameter.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
|Boolean
|fixed point
Port_1
— First input to multiply or divide
scalar | vector | matrix | N-D array
First input to multiply or divide, provided as a scalar, vector, matrix, or N-D array.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
|Boolean
|fixed point
Port_N
— Nth input to multiply or divide
scalar | vector | matrix | N-D array
Nth input to multiply or divide, provided as a scalar, vector, matrix, or N-D array.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
|Boolean
|fixed point
Output
Port_1
— Output computed by multiplying, dividing, or inverting inputs
scalar | vector | matrix | N-D array
Output computed by multiplying, dividing, or inverting inputs.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
|Boolean
|fixed point
Parameters
Main
Number of inputs
— Control number of inputs and type of operation
*/
(默认)|positive integer scalar |*
or/
for each input port
Control two properties of the block:
The number of input ports on the block
Whether each input is multiplied or divided into the output
When you specify:
1
or*
or/
The block has one input port. In element-wise mode, the block processes the input as described for theProduct of Elementsblock. In matrix mode, if the parameter value is
1
or*
, the block outputs the input value. If the value is/
, the input must be a square matrix (including a scalar as a degenerate case) and the block outputs the matrix inverse. SeeElement-Wise ModeandMatrix Modefor more information.Integer value > 1
The block has the number of inputs given by the integer value. The inputs are multiplied together in element-wise mode or matrix mode, as specified by theMultiplicationparameter. SeeElement-Wise ModeandMatrix Modefor more information.
Unquoted string of two or more
*
and/
charactersThe block has the number of inputs given by the length of the character vector. Each input that corresponds to a
*
character is multiplied into the output. Each input that corresponds to a/
character is divided into the output. The operations occur in element-wise mode or matrix mode, as specified by theMultiplicationparameter. SeeElement-Wise ModeandMatrix Modefor more information.
Programmatic Use
Block Parameter:Inputs |
Type:character vector |
Values:'2' | '*' | '**' | '*/' | '*/*' | ... |
Default:'*/' |
Multiplication
— Element-wise (.*) or Matrix (*) multiplication
Element-wise(.*)
(默认)|Matrix(*)
Specify whether the block performsElement-wise(.*)
orMatrix(*)
multiplication.
Programmatic Use
Block Parameter:Multiplication |
Type:character vector |
Values:'Element-wise(.*)' | 'Matrix(*)' |
Default:'Element-wise(.*)' |
Multiply over
— All dimensions or specified dimension
All dimensions
(默认)|Specified dimension
Specify the dimension to multiply over asAll dimensions
, orSpecified dimension
. When you selectSpecified dimension
, you can specify theDimensionas1
or2
.
Dependencies
To enable this parameter, setNumber of inputsto*
andMultiplicationtoElement-wise (.*)
.
Programmatic Use
Block Parameter:CollapseMode |
Type:character vector |
Values:'All dimensions' | 'Specified dimension' |
Default:'All dimensions' |
Dimension
— Dimension to multiply over
1
(默认)|2
|...
|N
Specify the dimension to multiply over as an integer less than or equal to the number of dimensions of the input signal.
Dependencies
To enable this parameter, set:
Number of inputsto
*
Multiplicationto
Element-wise (.*)
Multiply overto
Specified dimension
Programmatic Use
Block Parameter:CollapseDim |
Type:character vector |
Values:'1' | '2' | ... |
Default:'1' |
Sample time
— Specify sample time as a value other than-1
-1
(默认)|scalar
Specify the sample time as a value other than -1. For more information, seeSpecify Sample Time.
Dependencies
This parameter is not visible unless it is explicitly set to a value other than-1
. To learn more, seeBlocks for Which Sample Time Is Not Recommended.
Programmatic Use
Block Parameter:SampleTime |
Type:character vector |
Values:scalar |
Default:'-1' |
Signal Attributes
Require all inputs to have the same data type
— Require that all inputs have the same data type
off
(默认)|on
Specify if input signals must all have the same data type. If you enable this parameter, then an error occurs during simulation if the input signal types are different.
Programmatic Use
Block Parameter:InputSameDT |
Type:character vector |
Values:'off' | 'on' |
Default:'off' |
Output minimum
——最小输出值范围检查
[]
(默认)|scalar
Lower value of the output range that Simulink®checks.
Simulink uses the minimum to perform:
Parameter range checking (seeSpecify Minimum and Maximum Values for Block Parameters) for some blocks.
Simulation range checking (seeSignal RangesandEnable Simulation Range Checking).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, seeOptimize using the specified minimum and maximum values(Simulink Coder).
Note
Output minimumdoes not saturate or clip the actual output signal. Use theSaturationblock instead.
Programmatic Use
Block Parameter:OutMin |
Type: character vector |
Values:'[ ]' | scalar |
Default:'[ ]' |
Output maximum
— Maximum output value for range checking
[]
(默认)|scalar
Upper value of the output range that Simulink checks.
Simulink uses the maximum value to perform:
Parameter range checking (seeSpecify Minimum and Maximum Values for Block Parameters) for some blocks.
Simulation range checking (seeSignal RangesandEnable Simulation Range Checking).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, seeOptimize using the specified minimum and maximum values(Simulink Coder).
Note
Output maximumdoes not saturate or clip the actual output signal. Use theSaturationblock instead.
Programmatic Use
Block Parameter:OutMax |
Type: character vector |
Values:'[ ]' | scalar |
Default:'[ ]' |
Output data type
— Specify the output data type
继承:Inherit via internal rule
(默认)|继承:Inherit via back propagation
|继承:Same as first input
|double
|single
|int8
|uint8
|int16
|uint16
|int32
|uint32
|fixdt(1,16)
|fixdt(1,16,0)
|fixdt(1,16,2^0,0)
|
Choose the data type for the output. The type can be inherited, specified directly, or expressed as a data type object such asSimulink.NumericType
. For more information, seeControl Signal Data Types.
When you select an inherited option, the block behaves as follows:
继承: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. For example, if the block multiplies an input of typeint8
by a gain ofint16
andASIC/FPGA
is specified as the targeted hardware type, the output data type issfix24
. IfUnspecified (assume 32-bit Generic)
, in other words, a generic 32-bit microprocessor, is specified as the target hardware, the output data type isint32
. If none of the word lengths provided by the target microprocessor can accommodate the output range, Simulink software displays an error in the Diagnostic Viewer.这并不总是可能的opti的软件mize 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
继承:Same as input
.Explicitly specify a default data type such as
fixdt(1,32,16)
and then use the Fixed-Point Tool to propose data types for your model. For more information, seefxptdlg
.To specify your own inheritance rule, use
继承:Inherit via back propagation
and then use aData Type Propagationblock. Examples of how to use this block are available in the Signal Attributes libraryData Type Propagation Examplesblock.
继承:Inherit via back propagation
— Use data type of the driving block.继承:Same as first input
— Use data type of first input signal.
Programmatic Use
Block Parameter:OutDataTypeStr |
Type: character vector |
Values:'Inherit: Inherit via internal rule |'Inherit: Same as first input' |'Inherit: Inherit via back propagation' |'double' |'single' |'int8' |'uint8' |'int16' |'uint16' ,'int32' |'uint32' |'fixdt(1,16)' |'fixdt(1,16,0)' |'fixdt(1,16,2^0,0)' |'' |
Default:'Inherit: Inherit via internal rule' |
Lock output data type setting against changes by the fixed-point tools
— Prevent fixed-point tools from overriding Output data type
off
(默认)|on
Select this parameter to prevent the fixed-point tools from overriding theOutputdata type you specify on the block. For more information, seeUse Lock Output Data Type Setting(Fixed-Point Designer).
Programmatic Use
Block Parameter:LockScale |
Type:character vector |
Values:'off' | 'on' |
Default:'off' |
Integer rounding mode
— Rounding mode for fixed-point operations
Floor
(默认)|Ceiling
|Convergent
|Nearest
|Round
|Simplest
|Zero
Select the rounding mode for fixed-point operations. You can select:
-
Ceiling
-
Rounds 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 Fixed-Point Designer™
convergent
function. -
Floor
-
Rounds 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 Fixed-Point 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 Fixed-Point Designer
round
function. -
Simplest
-
Chooses between rounding toward floor and rounding toward zero to generate rounding code that is as efficient as possible.
-
Zero
-
Rounds number toward zero. Equivalent to the MATLAB
fix
function.
For more information, seeRounding(Fixed-Point Designer).
Block parameters always round to the nearest representable value. To control the rounding of a block parameter, enter an expression using a MATLAB rounding function into the mask field.
Programmatic Use
Block Parameter:RndMeth |
Type:character vector |
Values:'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero' |
Default:'Floor' |
Saturate on integer overflow
— Method of overflow action
off
(默认)|on
Specify whether overflows saturate or wrap.
Action | Rationale | Impact on Overflows | Example |
---|---|---|---|
Select this check box ( |
Your model has possible overflow, and you want explicit saturation protection in the generated code. |
Overflows saturate to either the minimum or maximum value that the data type can represent. |
The maximum value that the |
Do not select this check box ( |
You want to optimize efficiency of your generated code. You want to avoid overspecifying how a block handles out-of-range signals. For more information, seeCheck for Signal Range Errors. |
Overflows wrap to the appropriate value that is representable by the data type. |
The maximum value that the |
When you select this check box, saturation applies to every internal operation on the block, not just the output, or result. Usually, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.
Programmatic Use
Block Parameter:SaturateOnIntegerOverflow |
Type:character vector |
Values:'off' | 'on' |
Default:'off' |
模型的例子
Block Characteristics
Data Types |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Expected Differences Between Simulation and Code Generation
These conditions may yield different results between simulation and the generated code:
TheDivideblock inputs contain a
NaN
orinf
valueTheDivideblock generates
NaN
orinf
during execution
This difference is due to the nonfiniteNaN
orinf
values. In such cases, inspect your model configuration and eliminate the conditions that produceNaN
orinf
.
Code Optimizations
TheSimulink Coder™build process provides efficient code for matrix inverse and division operations. This table describes the benefits and when each benefit is available.
Benefit | Small Matrices (2-by-2 to 5-by-5) |
Medium Matrices (6-by-6 to 20-by-20) |
Large Matrices (larger than 20-by-20) |
---|---|---|---|
Faster code execution time, compared to R2011a and earlier releases | Yes | No | Yes |
Reduced ROM and RAM usage, compared to R2011a and earlier releases | Yes, for real values | Yes, for real values | Yes, for real values |
Reuse of variables | Yes | Yes | Yes |
Dead code elimination | Yes | Yes | Yes |
Constant folding | Yes | Yes | Yes |
Expression folding | Yes | Yes | Yes |
Consistency withMATLAB编码器results | Yes | Yes | Yes |
For blocks that have three or more inputs of different dimensions, the code might include an extra buffer to store temporary variables for intermediate results.
HDL Code Generation
Generate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.
For more information about HDL code generation, seeDivide.
PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.
Fixed-Point Conversion
浮点算法转换为定点using Fixed-Point Designer™.
See Also
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)