Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Switch - Switch output between first input and third input based on value of second input

Library

Signal Routing

Description

The Switch block passes through the first input or the third input based on the value of the second input. The first and third inputs are called data inputs. The second input is called the control input. See How to Rotate a Block in the Simulink User's Guide for a description of the port order for various block orientations.

You select the condition under which the block passes the first input with the Criteria for passing first input parameter.

To immediately back propagate a known output data type to the first and third input ports, set the Output data type parameter to Inherit: Inherit via internal rule and select the Require all data port inputs to have the same data type check box.

Data Type Support

The control signal can be of any data type that Simulink supports, including fixed-point and enumerated types. The control signal cannot be complex. If the control signal is enumerated, the block Threshold parameter must be a value of the same enumerated type.

The data signals can be of any data type that Simulink supports. If either data signal is of an enumerated type, the other must be of the same enumerated type.

For more information, see Data Types Supported by Simulink in the Simulink User's Guide.

Parameters and Dialog Box

The Main pane of the Switch block dialog box appears as follows:

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

Criteria for passing first input

Select the condition under which the block passes the first input. If the control input meets the condition set in the Criteria for passing first input parameter, the block passes the first input. Otherwise, the block passes the third input.

Settings

Default: u2 >= Threshold

u2 >= Threshold

Checks whether the control input is greater than or equal to the threshold value.

u2 > Threshold

Checks whether the control input is greater than the threshold value.

u2 ~=0

Checks whether the control input is nonzero.

    Note   The Switch block does not support u2 ~=0 mode for enumerated data types.

Tip

When the control input is a Boolean signal, use one of these combinations of condition and threshold value:

Otherwise, the Switch block ignores threshold values and uses the Boolean value for signal routing. For a value of 1, the block passes the first input, and for a value of 0, the block passes the third input. A warning message that describes this behavior also appears in the MATLAB Command Window.

Dependencies

Selecting u2 ~=0 disables the Threshold parameter.

Command-Line Information

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

Threshold

Assign the switch threshold that determines which input the block passes to the output.

Settings

Default: 0

Minimum: value from the Output minimum parameter

Maximum: value from the Output maximum parameter

Dependencies

Setting Criteria for passing first input to u2 ~=0 disables this parameter.

Command-Line Information

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

Enable zero-crossing detection

Select to enable zero-crossing detection.

Settings

Default: On

On

Enables zero-crossing detection.

Off

Disables zero-crossing detection.

Command-Line Information

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

Sample time (-1 for inherited)

Enter the discrete interval between sample time hits or specify another appropriate sample time such as continuous or inherited.

Settings

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.

Command-Line Information

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

Require all data port inputs to have the same data type

Require all data inputs to have the same data type.

Settings

Default: Off

On

Requires all data inputs to have the same data type.

Off

Does not require all data inputs to 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

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

See Also

For more information, see Fixed-Point Tool and Fixed-Point Advisor in the Simulink Fixed Point documentation.

Integer rounding mode

Select the rounding mode for fixed-point operations.

Settings

Default: Floor

Ceiling

Rounds both positive and negative numbers toward positive infinity.

Convergent

Rounds number to the nearest representable value. If a tie occurs, round to the nearest even stored value.

Floor

Rounds both positive and negative numbers toward negative infinity.

Nearest

Rounds number to the nearest representable value. If a tie occurs, round toward positive infinity.

Round

Rounds number to the nearest representable value. If a tie occurs, round positive numbers toward positive infinity and round negative numbers toward negative infinity.

Simplest

Provides for an optimization of the rounding code for several blocks.

Zero

Rounds number toward zero.

Command-Line Information

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

See Also

For more information, see Rounding in the Simulink Fixed Point User's Guide.

Saturate on integer overflow

Specify whether overflows saturate.

Settings

Default: Off

On

Specifies overflows saturate.

Off

Specified overflows do not saturate.

Tips

Command-Line Information

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

Allow different data input sizes

Select this check box to allow input signals with different sizes.

Settings

Default: Off

On

Allows input signals with different sizes, and propagates the input signal size to the output signal.

Off

Inputs signals must be the same size.

Command-Line Information

Parameter: AllowDiffInputSignals
Type: string
Value: 'on' | 'off'
Default: 'off'

Output minimum

Specify the minimum value that the block should output.

Settings

Default: []

The default value, [], is equivalent to -Inf.

Simulink uses this value to perform:

Tip

This number must be a double scalar value.

Command-Line Information

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

Output maximum

Specify the maximum value that the block should output.

Settings

Default: []

The default value, [], is equivalent to Inf.

Simulink uses this value to perform:

Tip

This number must be a double scalar value.

Command-Line Information

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

Output data type

Specify the output data type.

Settings

Default:

Inherit: Inherit via internal rule

This option appears only for some blocks. Simulink chooses a combination of output scaling and data type that requires the smallest amount of memory. The choices are consistent with accommodating the calculated output range, maintaining the output precision of the block, and the word size of the targeted hardware implementation specified for the model.

If you set the Device type parameter on the Hardware Implementation configuration parameters pane to ASIC/FPGA, Simulink chooses the output data type without regard to hardware constraints. Otherwise, Simulink 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 you specify ASIC/FPGA as the targeted hardware type, the output data type is sfix24.

If you select Unspecified (assume 32-bit Generic) for a generic 32-bit microprocessor 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 displays an error message in the Simulation Diagnostics Viewer.

Inherit: Inherit from 'Constant value'

Usees data type of Constant value parameter. This option appears only for some blocks.

Inherit: Inherit via back propagation

Uses data type of the driving block.

Inherit: Same as input

Uses data type of sole input signal. This option appears only for some blocks.

Inherit: Same as first input

Uses data type of first input signal. This option appears only for some blocks.

Inherit: Same as accumulator

Specifies output data type is the same as accumulator data type. This option appears for some blocks.

double

Specifies output data type is double.

single

Specified output data type is single.

int8

Specifies output data type is int8.

uint8

Specifies output data type is uint8.

int16

Specifies output data type is int16.

uint16

Specifies output data type is uint16.

int32

Specifies output data type is int32.

uint32

Specifies output data type is unt32.

fixdt(1,16,0)

Specifies output data type is fixed point fixdt(1,16,0).

fixdt(1,16,2^0,0)

Specifies output data type is fixed point fixdt(1,16,2^0,0).

Enum: <class name>

Uses an enumerated data type, for example, Enum: BasicColors. This option appears only for some blocks.

<data type expression>

Uses a data type object, for example, Simulink.NumericType.

Command-Line Information

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

See Also

See Specifying Block Output Data Types in the Simulink User's Guide for more information.

Mode

Select the category of data to specify.

Settings

Default:

Inherit

Specifies inheritance rules for data types. Selecting Inherit enables a list of 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

Specifies built-in data types. Selecting Built in enables a list of 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

Specifies fixed-point data types.

Enumerated

Specifies enumerated data types. This option is available only on some blocks. Selecting Enumerated enables a list of possible values, which can vary by block:

  • <class name>

Expression

Specifies expressions that evaluate to data types. Selecting Expression enables a list of possible values, which can vary by block:

  • <data type expression>

Dependencies

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 Using the Data Type Assistant in the Simulink User's Guide.

Signedness

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

Settings

Default: Signed

Signed

Specifies the fixed-point data as signed.

Unsigned

Specifies the fixed-point data as unsigned.

Dependencies

Selecting Mode > Fixed point enables this parameter.

Command-Line Information

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

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Word length

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

Settings

Default: 16

Minimum: 0

Maximum: 32

Large word sizes represent large values with greater precision than small word sizes.

Dependencies

Selecting Mode > Fixed point enables this parameter.

Command-Line Information

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

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Scaling

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

Settings

Default:

Binary point

Specifies binary point location.

Slope and bias

Enters slope and bias.

Best precision

Specifies best-precision values. This option appears only for some blocks.

Integer

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.

Dependencies

Selecting Binary point enables:

Selecting Slope and bias enables:

Command-Line Information

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

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

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.

Command-Line Information

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

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

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.

Command-Line Information

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

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

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.

Command-Line Information

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

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Bus Support

The Switch block is a bus-capable block. The data inputs can be virtual or nonvirtual bus signals subject to the following restrictions:

You can use a Rate Transition block to change the sample time of an individual signal, or of all signals in a bus. See Using Composite Signals and Bus-Capable Blocks for more information.

Characteristics

Bus-capableYes, with restrictions

Direct Feedthrough

Yes

Sample Time

Specified in the Sample time parameter

Scalar Expansion

Yes

Dimensionalized

Yes

Multidimensionalized

Yes

Zero-Crossing Detection

Yes, if enabled

See Also

Multiport Switch

  


Related Products & Applications

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