This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Constant

Generate constant value

  • Library:
  • Simulink / Commonly Used Blocks

    Simulink / Sources

    HDL Coder / Commonly Used Blocks

    HDL Coder / Sources

Description

The Constant block generates a real or complex constant value signal. Use this block to provide a constant signal input. The block generates scalar, vector, or matrix output, depending on:

  • The dimensionality of the Constant value parameter

  • The setting of the Interpret vector parameters as 1-D parameter

The output of the block has the same dimensions and elements as the Constant value parameter. If you specify for this parameter a vector that you want the block to interpret as a vector, select the Interpret vector parameters as 1-D check box. Otherwise, if you specify a vector for the Constant value parameter, the block treats that vector as a matrix.

Tip

To output a constant enumerated value, consider using the Enumerated Constant block instead. The Constant block provides block parameters that do not apply to enumerated types, such as Output minimum and Output maximum.

Using Bus Objects as the Output Data Type

The Constant block supports nonvirtual buses as the output data type. Using a bus object as the output data type can help simplify your model. If you use a bus object as the output data type, set the Constant value to 0 or to a MATLAB® structure that matches the bus object.

Using Structures for the Constant Value of a Bus

The structure you specify must contain a value for every element of the bus represented by the bus object. The block output is a nonvirtual bus signal.

You can use the Simulink.Bus.createMATLABStruct to create a full structure that corresponds to a bus.

You can use Simulink.Bus.createObject to create a bus object from a MATLAB structure.

If the signal elements in the output bus use numeric data types other than double, you can specify the structure fields by using typed expressions such as uint16(37) or untyped expressions such as 37. To control the field data types, you can use the bus object as the data type of a Simulink.Parameter object. To decide whether to use typed or untyped expressions, see Control Data Types of Initial Condition Structure Fields.

Setting Configuration Parameters to Support Using a Bus Object Data Type

To enable the use of a bus object as an output data type, before you start a simulation, set Configuration Parameters > Diagnostics > Data Validity > Advanced parameters > Underspecified initialization detection to Simplified. For more information, see Underspecified initialization detection.

Ports

Output

expand all

Constant value, specified as a real or complex valued scalar, vector, matrix, or N-D array. By default, the Constant block outputs a signal whose dimensions, data type, and complexity are the same as those of the Constant value parameter. However, you can specify the output to be any data type that Simulink® supports, including fixed-point and enumerated data types.

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 more information, see Simulink.BusElement.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean | fixed point | enumerated | bus

Parameters

expand all

Main

Specify the constant value output of the block.

  • You can enter any expression that MATLAB evaluates as a matrix, including the Boolean keywords true and false.

  • If you set the Output data type to be a bus object, you can specify one of these options:

    • A full MATLAB structure corresponding to the bus object

    • 0 to indicate a structure corresponding to the ground value of the bus object

    For details, see Using Bus Objects as the Output Data Type.

  • For nonbus data types, Simulink converts this parameter from its value data type to the specified output data type offline, using a rounding method of nearest and overflow action of saturate.

Programmatic Use

Block Parameter: Value
Type: character vector
Value: scalar | vector | matrix | N-D array
Default: '1'

Select this check box to output a vector of length N if the Constant value parameter evaluates to an N-element row or column vector.

  • When you select this check box, the block outputs a vector of length N if the Constant value parameter evaluates to an N-element row or column vector. For example, the block outputs a matrix of dimension 1-by-N or N-by-1.

  • When you clear this check box, the block does not output a vector of length N if the Constant value parameter evaluates to an N-element row or column vector.

Programmatic Use

Block Parameter: VectorParams1D
Type: character vector
Values: 'on' | 'off'
Default: 'on'

Specify the interval between times that the Constant block output can change during simulation (for example, due to tuning the Constant value parameter).

The default value of inf indicates that the block output can never change. This setting speeds simulation and generated code by avoiding the need to recompute the block output.

See Specify Sample Time for more information.

Programmatic Use

Block Parameter: SampleTime
Type: character vector
Values: scalar | vector
Default: 'inf'

Signal Attributes

Specify the lower value of the output range that Simulink checks as 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 parameter for a bus element, see Simulink.BusElement.

Simulink uses the minimum to perform:

Note

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

Programmatic Use

Block Parameter: OutMin
Type: character vector
Values: scalar
Default: '[ ]'

Specify the upper value of the output range that Simulink checks as 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 parameter for a bus element, see Simulink.BusElement.

Simulink uses the maximum value to perform:

Note

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

Programmatic Use

Block Parameter: OutMax
Type: character vector
Values: scalar
Default: '[ ]'

Specify the output data type. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: OutDataTypeStr
Type: character vector
Values: 'Inherit: Inherit from 'Constant value'' | 'Inherit: Inherit via back propagation' | 'double' | 'single' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'boolean' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | 'Enum: <class name>' | 'Bus: <object name>'
Default: 'Inherit: Inherit from 'Constant value''

Select this parameter to prevent the fixed-point tools from overriding the Output data type you specify on the block. For more information, see Use Lock Output Data Type Setting (Fixed-Point Designer).

Programmatic Use

Block Parameter: LockScale
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Block Characteristics

Data Types

Boolean | bus | double | enumerated | fixed point | integer | single

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Fixed-Point Conversion
Convert floating-point algorithms to fixed point using Fixed-Point Designer™.

Introduced before R2006a