Documentation

我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

Divide

Divide one input by another

Library

Math Operations

Description

The Product and Product of Elements blocks are variants of the Divide block.

Supported Block Operations

The Divide block 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. The Divide block is functionally a Product block that has two block parameter values preset:

  • Multiplication: Element-wise(.*)

  • Number of Inputs: */

Setting non-default values for either of those parameters can change a Divide block to be functionally equivalent to a Product block or a Product of Elements block. See the documentation of those two blocks for more information.

Expected Differences Between Simulation and Code Generation

If any of the Divide block inputs contains a NaN or inf value, or if the block generates NaN or inf during execution, you might see different results when you compare the block simulation results with the generated code. This difference is due to the nonfinite NaN or inf values. In such cases, inspect your model configuration and eliminate the conditions that produce NaN or inf.

Code Optimizations

The Simulink® Coder™ build process provides efficient code for matrix inverse and division operations. The following summary describes the benefits and when each benefit is available:

BenefitSmall 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 releasesYesNoYes
Reduced ROM and RAM usage, compared to R2011a and earlier releasesYes, for real valuesYes, for real valuesYes, for real values
Reuse of variablesYesYesYes
Dead code eliminationYesYesYes
Constant foldingYesYesYes
Expression foldingYesYesYes
Consistency with MATLAB® Coder resultsYesYesYes

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.

Parameters

Show data type assistant

Display the Data Type Assistant.

Settings

The Data Type Assistant helps you set the Output data type parameter.

For more information, see Control Signal Data Types.

Number of inputs

Control two properties of the block:

  • The number of input ports on the block

  • Whether each input is multiplied or divided into the output

Settings

Default: */

  • 1 or * or /

    Has one input. In element-wise mode, processes the input as described for the Product of Elements block. 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. See Element-wise Mode and Matrix Mode for more information.

  • Integer value > 1

    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 the Multiplication parameter. See Element-wise Mode and Matrix Mode for more information.

  • Unquoted string of two or more * and / characters

    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 the Multiplication parameter. See Element-wise Mode and Matrix Mode for more information.

Dependency

Setting Number of inputs to * and selecting Element-wise(.*) for Multiplication enables the parameter Multiply over.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Multiplication

Specify whether the Product block operates in Element-wise mode or Matrix mode.

Settings

Default: Element-wise(.*)

Element-wise(.*)

Operate in Element-wise mode.

Matrix(*)

Operate in Matrix mode.

Dependency

Selecting Element-wise(.*) and setting Number of inputs to * enable the following parameter:

  • Multiply over

Command-Line Information

See Block-Specific Parameters for the command-line information.

Multiply over

Affect multiplication on matrix input.

Settings

Default: All dimensions

All dimensions

Output a scalar that is product of all elements of the matrix, or the product of their inverses, depending on the value of Number of inputs.

Specified dimension

Output a vector, the composition of which depends on the value of the Dimension parameter.

Dependencies

  • Enable this parameter by selecting Element-wise(.*) for Multiplication and setting Number of inputs to * or 1 or /.

  • Setting this parameter to Specified dimension enables the Dimension parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Dimension

Affect multiplication on matrix input.

Settings

Default: 1

Minimum: 1

Maximum: 2

1

Output a vector that contains an element for each column of the input matrix.

2

Output a vector that contains an element for each row of the input matrix.

Tips

Each element of the output vector contains the product of all elements in the corresponding column or row of the input matrix, or the product of the inverses of those elements, depending on the value of Number of inputs:

  • 1 or *

    Multiply the values of the column or row elements

  • /

    Multiply the inverses of the column or row elements

Dependency

Enable this parameter by selecting Specified dimension for Multiply over.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Sample time

Require all inputs to have the same data type

Require that all inputs have the same data type.

Settings

Default: Off

On

Require that all inputs have the same data type.

Off

Do not require that all inputs have the same data type.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Lock output data type setting against changes by the fixed-point tools

Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor.

Settings

Default: Off

On

Locks the output data type setting for this block.

Off

Allows the Fixed-Point Tool and the Fixed-Point Advisor to change the output data type setting for this block.

Command-Line Information

Parameter: LockScale
Type: character vector
Value: 'off' | 'on'
Default: 'off'

See Also

For more information, see Use Lock Output Data Type Setting.

Integer rounding mode

Specify the rounding mode for fixed-point operations.

Settings

Default: Floor

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.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

For more information, see Rounding.

Saturate on integer overflow

Specify whether overflows saturate.

Settings

Default: Off

On

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.

Off

Overflows wrap to the appropriate value that the data type can represent.

For example, the number 130 does not fit in a signed 8-bit integer and wraps to -126.

Tips

  • 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 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.

Command-Line Information

Parameter: SaturateOnIntegerOverflow
Type: character vector
Value: 'off' | 'on'
Default: 'off'

Output minimum

Lower value of the output range that Simulink checks.

Settings

Default: [] (unspecified)

Specify this number as a finite, real, double, scalar value.

Simulink uses the minimum to perform:

    Note:   Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead.

Command-Line Information

Parameter: OutMin
Type: character vector
Value: '[ ]'
Default: '[ ]'

Output maximum

Upper value of the output range that Simulink checks.

Settings

Default: [] (unspecified)

Specify this number as a finite, real, double, scalar value.

Simulink uses the maximum value to perform:

    Note:   Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead.

Command-Line Information

Parameter: OutMax
Type: character vector
Value: '[ ]'
Default: '[ ]'

Output data type

Specify the output data type.

Settings

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 Fixed-Point 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.

Inherit: Inherit via back propagation

Use data type of the driving block.

Inherit: Same as first input

Use data type of the first input signal.

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.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

For more information, see Control Signal Data Types.

Mode

Select the category of data to specify.

Settings

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

Built in

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

Fixed-point 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.

Dependency

Clicking the Show data type assistant button enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specify Data Types Using Data Type Assistant.

Data type override

Specify data type override mode for this signal.

Settings

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 fixed-point data type specified for the signal.

Tip

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.

Dependency

This parameter appears only when the Mode is Built in or Fixed point.

Signedness

Specify whether you want the fixed-point data as signed or unsigned.

Settings

Default: Signed

Signed

Specify the fixed-point data as signed.

Unsigned

Specify the fixed-point data as unsigned.

Dependencies

Selecting Mode > Fixed point enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Word length

Specify the bit size of the word that holds the quantized integer.

Settings

Default: 16

Minimum: 0

Maximum: 32

Dependencies

Selecting Mode > Fixed point enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Scaling

Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.

Settings

Default: Best precision

Binary point

Specify binary point location.

Slope and bias

Enter slope and bias.

Best precision

Specify best-precision values.

Dependencies

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 Also

For more information, see Specifying a Fixed-Point Data Type.

Fraction length

Specify fraction length for fixed-point data type.

Settings

Default: 0

Binary points can be positive or negative integers.

Dependencies

Selecting Scaling > Binary point enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Slope

Specify slope for the fixed-point data type.

Settings

Default: 2^0

Specify any positive real number.

Dependencies

Selecting Scaling > Slope and bias enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Bias

Specify bias for the fixed-point data type.

Settings

Default: 0

Specify any real number.

Dependencies

Selecting Scaling > Slope and bias enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Examples

The following examples show the output of the Divide block for some typical inputs using default block parameter values.

Introduced before R2006a


Was this topic helpful?