setInitialState - Specify initial state for simulation using
SimulationInput or Simulation
object - MATLAB ([original](https://www.mathworks.com/help/simulink/slref/simulink.simulationinput.setinitialstate.html)) ([raw](?raw))
Open the model vdp
.
mdl = "vdp"; open_system(mdl);
Configure the model to save the final operating point at the end of simulation.
- On the Modeling tab, under Setup, click Model Settings.
- In the Configuration Parameters dialog box, select the Data Import/Export pane.
- On the Data Import/Export tab, select Final states and Save final operating point.
- Click OK.
Alternatively, create a Simulink.SimulationInput
object to store the parameter values for the simulation. Then, use the setModelParameter
function to specify the parameter values to use in the simulation.
simIn = Simulink.SimulationInput(mdl);
simIn = setModelParameter(simIn,"SaveFinalState","on"); simIn = setModelParameter(simIn,"SaveOperatingPoint","on");
Set the stop time for the simulation to 10 seconds. On the Simulation tab, under Simulate, in the Stop Time box, enter 10
, or use the setModelParameter
function to specify the value of the StopTime
parameter for the simulation.
simIn = setModelParameter(simIn,"StopTime","10");
Simulate the model.
To view the simulation results, double-click the Scope block in the model. The plot in the Scope displays the values of the signals x1
and x2
over the 10-second simulation.
Resume the simulation by using the operating point you saved at the end of the first simulation as the initial operating point for the second simulation.
Get the final operating point from the first simulation from the Simulink.SimulationOutput
object out
.
Specify the operating point as the initial state for the simulation.
- On the Modeling tab, under Setup, click Model Settings.
- In the Configuration Parameters dialog box, on the Data Import/Export pane, select Initial state.
- In the text box, enter
vdpOP
. - Click OK.
Alternatively, create another Simulink.SimulationInput
object to configure this simulation. Then, use the setInitialState
function to specify the initial state.
simIn2 = Simulink.SimulationInput(mdl);
simIn2 = setInitialState(simIn2,vdpOP);
Set the stop time for this simulation to 20. On the Simulation tab, under Simulate, in the Stop Time box, enter 20
, or use the setModelParameter
function to specify the value of the StopTime
parameter for the simulation.
simIn2 = setModelParameter(simIn2,"StopTime","20");
Simulate the model again, resuming the prior simulation by starting this simulation from the final operating point saved in the first simulation.
The plot in the Scope window updates to show the data from this simulation. The time axis starts at 0
and goes to the simulation stop time of 20
. Because this simulation started from the initial operating point from the first simulation, which ended after 10 simulation seconds, the plot shows the values of the signals x1
and x2
only between simulation time 10 seconds and 20 seconds.