Main Content

State Information

Simulation State Information

Some blocks maintain state information that they use during simulation. For example, the state information for aUnit Delayblock is the output signal value from the previous simulation step. The block uses the state information to calculate the output value for the current simulation step.

Some examples of how saved state information is used include:

  • Stopping a simulation for a model and using the saved state information as input when you restart the simulation.

  • Simulating one model and using the saved state information as input for the simulation of another model that builds on the results of the first model.

  • Examining changes in state information throughout a simulation.

Types of State Information

You can save these kinds of state information.

Type of State Information Description Configuration Parameters in Data Import/Export Pane
States for each simulation step State information of blocks (referred to as partial state data) at each time step of a simulation States
Final state State information of blocks at the end of the simulation Final states
Final state withModelOperatingPoint Final state with aModelOperatingPointobject that captures additional internal information that Simulink®uses during simulation Final StatesandSave final operating point

ModelOperatingPoint提供了更完整的最终的模拟状态信息rmation than final states information by itself does. However, if the requirements and limitations of usingModelOperatingPointdo not meet your modeling requirements, save final state information withoutModelOperatingPoint.

Comparison of Operating Point and Final State Logging

Characteristic Final State Final State with Operating Point

Simulation mode

Supports all simulation modes

Supports all simulation modes

Model reference

State Information for Referenced Models

SeeModel Referencing.

Resumed simulation

Not supported

Supported.

Saved state data

Only logged states — the continuous and discrete states of blocks — which are a subset of the complete simulation state of the model

User data, run-time parameters, or logs of the model not saved

Complete state information.

Does not save user data, run-time parameters, or logs of the model.

Block output

User data, run-time parameters, or logs of the model not saved

Simulink tries to save the output of a block as part of aModelOperatingPointobject even if S-functions declare that noModelOperatingPointobjects exist in the block. If the block output is of custom type, Simulink displays an error.

Readability

Use structure with time format for best readability

To examine a simplified view of the data, consider using theloggedStatesproperty of theSimulink.op.ModelOperatingPointclass.

Restoring state data

Can save and restore in different simulation modes. If logged state information is not sufficient, you can obtain different results in the normal mode and the accelerator mode.

Cannot save in normal mode and restore in accelerator mode, or conversely save in accelerator mode and restore in normal mode.

Restoring multiple states

You can initialize only one out of multiple logged states in the model.

You restore all states in the model. You cannot load a subset of states.

Structural changes

You can make structural changes between simulation and restoring the simulation.

You cannot make structural changes to the model between when you save theModelOperatingPointobject and when you restore the simulation using theModelOperatingPointobject. For example, you cannot add or remove a block after saving theModelOperatingPointobject without repeating the simulation and saving the newModelOperatingPointobject.

Input tomodelfunction

To input to model function, useArrayformat with non-complex data of typedouble.

You cannot input theModelOperatingPointobject to model function.

Code generation

Supported

Not supported.

For bothModelOperatingPointand final state logging, Simulink saves state information at one of these points:

  • At the final time step

  • At the execution time at which the simulation paused or stopped

For additional information aboutModelOperatingPoint, seeLimitations of Saving and Restoring Operating Point.

Format for State Information Saved Without Operating Point

If you do not use theModelOperatingPointfor saving state information, then useConfiguration Parameters>Data Import/Export>Formatto specify the data format for the saved state information.

You can setFormatto:

  • Dataset(default)

  • Array

  • Structure

  • Structure with time

The default setting for theFormatparameter isDataset. TheDatasetformat:

  • Stores logged data intimeseriesortimetableobjects. You can work with data saved in atimeseriesortimetableobject in MATLAB®without a Simulink license.

  • Supports logging multiple data values for a given time step, which can be required for logging data in aFor Iterator Subsystem, aWhile Iterator Subsystem, and Stateflow®.

  • Does not support logging states inside a function-call subsystem or during rapid accelerator simulations.

  • Does not support code generation.

Signal logging always uses theDatasetformat. Logging states data using theDatasetformat allows you to post-process simulation data without writing custom code for different types of logged data. When you log states using theDatasetformat, the data also automatically streams to the Simulation Data Inspector during simulation.

TheArrayoption for theFormatparameter exists for backward compatibility with models developed in earlier releases, when Simulink supported only theArray格式日志状态信息。的顺序signals within the array depends on the block sorted order, which can change from one simulation to another when you change any of the following:

  • The model (even without changing the signal)

  • The simulation mode

  • The code generation mode

The variation in signal order can present challenges when post-processing the logged data.

TheStructureandStructure with timeformats are useful when using state information to initialize a model for simulation, allowing you to:

  • Associate initial state values directly with the full path name to the states. This association eliminates errors that can occur if Simulink reorders the states, but the order of the initial state array does not change correspondingly.

  • Assign a different data type to the initial value of each state.

  • Initialize only a subset of the states.

State Information for Referenced Models

When Simulink saves states in the structure or structure-with-time format, it adds aninReferencedModelsubfield to thesignalsfield of the structure. The value of this additional subfield is true (1) if thesignalsfield records the final state of a block that resides in the referenced model. For example:

xout.signals(1)
ans = values: [101x1 double] dimensions: 1 label: 'DSTATE' blockName: [1x66 char] inReferencedModel: 1

If the signals field records a referenced model state, itsblockNamesubfield contains a compound path of a top model path and a referenced model path. The top model path is the path from the model root to theModelblock that references the referenced model. The referenced model path is the path from the referenced model root to the block whose state thesignalsfield records. The compound path uses a | character to separate the top and referenced model paths. For example:

>> xout.signals(1).blockName
ans = sldemo_mdlref_basic/CounterA|sldemo_mdlref_counter/Previous Output

See Also

Classes

Related Topics