Main Content

Simulink.SimulationData.State

R2026b

Container for state logging information

Description

The software uses Simulink.SimulationData.State objects to store state logging information during simulation. Simulink.SimulationData.State objects contain information about the source block the state data is coming from and the type of state.

Creation

Simulating a model that logs state data creates one or more Simulink.SimulationData.State objects.

Description

st = Simulink.SimulationData.State creates an empty Simulink.SimulationData.State object.

example

Properties

expand all

Name of State object to use for name-based access, specified as a string or character vector.

When you create an empty State object and do not specify a name, no name is assigned.

When a State object is created during simulation, the Name property of the State object is specified by the State name parameter of the block from which state information is logged. Some blocks in the Discrete library, such as the Unit Delay block, automatically name the State object DSTATE when the State name parameter of the block is empty.

Block path of source block for State object, specified as a Simulink.SimulationData.BlockPath object.

This property is read-only.

Type of state, returned as one of these values:

  • 'CSTATE' – Continuous state

  • 'DSTATE' – Discrete state

Logged time and data, specified as one of these values:

  • A MATLAB® timeseries object

  • A MATLAB timetable object

  • A structure of MATLAB timeseries objects (for bus signals)

  • A structure of MATLAB timetable objects (for bus signals)

  • An array of structures of MATLAB timeseries objects (for array of buses signals)

  • An array of structures of MATLAB timetable objects (for array of buses signals)

  • An array of MATLAB timeseries objects (for nonbus signals in a For Each subsystem)

  • A cell array of MATLAB timetable objects (for nonbus signals in a For Each subsystem)

Object Functions

plotPlot data in Simulation Data Inspector

Examples

collapse all

Access state data from a simulation output using a Simulink.SimulationData.State object.

Simulate the model and access the state information. When you log data using a single simulation output, the software stores state data in the Simulink.SimulationOutput object in the property named xout by default.

out = sim("myModel");
out = 

  Simulink.SimulationOutput:

                logsout: [1x1 Simulink.SimulationData.Dataset] 
                   tout: [87x1 double] 
                 xFinal: [1x1 Simulink.SimulationData.Dataset] 
                   xout: [1x1 Simulink.SimulationData.Dataset] 
                   yout: [1x1 Simulink.SimulationData.Dataset] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char] 
myStates = out.xout;

Get the first logged state and access the logged data.

myState = myStates{1};
myState.Values;

The software saves final state information with the default variable name xFinal. When you log only final states, access that data in a similar way.

myFinalStates = out.xFinal;

Version History

Introduced in R2015a