Load State Information
Import Initial States
To initialize a simulation, you can use:
Final state information (with or without
ModelOperatingPointobject) from a previous simulation
State information that you create in MATLAB®
Use Configuration Parameters > Data Import/Export parameters to import initial states.
Enable the Initial state parameter.
In the Initial state edit box, enter the name of the variable for the state information that you want to use for initialization.
The initial values that the variable specifies override the initial state values that the blocks in the model specify in initial condition parameters.
You can specify
Dataset, structure, or structure with time
Initialize a State
You can initialize a specific state. This example creates an initial state structure for
x2 state of the
vdp model. The
x1 state is not initialized in the structure. Therefore, during
simulation, Simulink® uses the value in the Integrator block associated with the
Open the model.
SaveFormatmodel argument to
Obtain an initial state structure.
states = Simulink.BlockDiagram.getInitialState('vdp');
Set the initial value of the signals structure element associated with
states.signals(2).values = 2;
Remove the signals structure element associated with
states.signals(1) = ;
statesvariable for the
vdpmodel. Select the initial state configuration parameter.
Simulate the model and examine the initial values of
states = struct with fields: time: 0 signals: [1×1 struct]
ans = struct with fields: values: 2 dimensions: 1 label: 'CSTATE' blockName: 'vdp/x2' stateName: '' inReferencedModel: 0 sampleTime: [0 0]
When you simulate the model, both states have the initial value of 2. The initial value
x2 state is assigned in the
while the initial value of the
x1 state is assigned in its
Initialize States in Referenced Models
To initialize the states of a top model and the models that it references, use the structure or structure with time format or use operating point.
If the top model is in rapid accelerator mode, you cannot load discrete state data.