Main Content

State Reader

Read a block state

  • Library:
  • Simulink / Signal Routing

  • State Reader block

Description

The State Reader block reads the current state of a supported state owner block.

State Reader blocks can read state from these state owner blocks:

  • Discrete State-Space

  • Discrete-Time Integrator

  • Delay

  • Unit Delay

  • Discrete Transfer Fcn

  • Discrete Filter

  • Discrete FIR Filter

  • Integrator

  • Second-Order Integrator

  • Outport of conditional subsystem blocks such as Enabled Subsystem, Triggered Subsystem, and Function-Call Subsystem

  • S-Function with multiple discrete states

    To configure an S-Function block as a state owner block, each data type work vector must be declared as a discrete state vector using ssSetDWorkUsedAsDState and named using ssSetDWorkName or ssSetDWorkRTWIdentifier in mdlInitializeSizes.

Tip

You can determine whether a block is a supported state owner block by the value of the block's IsStateOwnerBlock parameter. The expression

get_param(blk,'IsStateOwnerBlock')
where blk is a block name or handle, returns 'on' if the block is a supported state owner block and 'off' otherwise.

To add a State Reader or State Writer block to your model, right-click on a state owner block and drag to an empty portion of the Simulink® canvas. When you release, a menu will appear. Select Create State Reader Block or Create State Writer Block.

Simulink canvas showing Unit Delay block and quick menu with Paste, Create State Reader Block, Create State Writer block, which is highlighted, and Cancel

After you create a State Reader or State Writer block, a diamond shape with an x inside it badge appears above the state owner block, and the name of the state owner block appears next to the State Reader or State Writer block.

Simulink canvas showing Unit Delay block with a badge above it, and a State Writer block with "Unit Delay" appearing next to it

A State Reader or State Writer block cannot remain in the same system as its state owner block. After you create a State Reader or State Writer block, cut and paste it to move it to the desired location within the model hierarchy.

Alternatively, you can add a State Reader or State Writer block to your model from the Simulink Library Browser, then set the State owner block parameter from the block parameters dialog.

Note

When you create a library block with a State Reader or State Writer block, you must also include the corresponding state owner block in the library block.

You can select a State Reader or State Writer block or a corresponding state owner block to highlight blocks related to it.

Ports

Output

expand all

State value read from a state owner block.

The dimension of the output is the dimension of the full state vector. Refer to the Initial conditions parameter for specific blocks. For example, for a Delay block with a Delay length of N, the State Reader block returns a state vector of length [1xN].

Data Types: single | double | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Parameters

expand all

Show the state owner block whose state this block is reading. To change the state owner block, select a block from the State Owner Selector Tree.

Programmatic Use

Block Parameter: StateOwnerBlock
Type: character vector
Value: '' | '<model path/block name>'
Default: ''

Block Characteristics

Data Types

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

Direct Feedthrough

no

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

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.