Main Content

setInitialState

Configure Simulink.SimulationInput object to set initial state for simulation

Description

example

simIn = setInitialState(simIn,xInitial) sets the value of the InitialState property for the Simulink.SimulationInput object simIn using the contents of the variable xInitial. Simulations run using the SimulationInput object simIn start from the initial state or operating point stored in the InitialState property of the object.

Examples

collapse all

Open the model sldemo_tonegen.

model = "sldemo_tonegen";
open_system(model);

Create a Simulink.SimulationInput object to specify parameter values to use in simulation.

simIn = Simulink.SimulationInput(model);

Configure the simulation to stop after ten seconds and save the final operating point in a variable named finalOP.

simIn = setModelParameter(simIn,"StopTime","10",...
    "SaveFinalState","on","SaveOperatingPoint","on",...
    "FinalStateName","finalOP");

Simulate the model using the settings configured on the SimulationInput object.

out = sim(simIn);

Access the saved operating point, returned as part of the single Simulink.SimulationOutput object.

finalOP = out.finalOP
finalOP = 
    Simulink.op.ModelOperatingPoint

    Operating point of the model 'sldemo_tonegen' at simulation time 10.

  Properties

    loggedStates
    description
    startTime (Read-only)
    snapshotTime (Read-only)

  Methods

    get
    set


Create a SimulationInput object to configure another simulation that uses the operating point saved from the first simulation.

simIn2 = Simulink.SimulationInput(model);

Configure the model to simulate to a stop time of twenty seconds.

simIn2 = setModelParameter(simIn2,"StopTime","20");

Use the setInitialState function to specify the initial state for the simulation using the Simulink.op.ModelOperatingPoint object saved from the first simulation.

simIn2 = setInitialState(simIn2,finalOP);

Simulate the model from the initial operating point.

out2 = sim(simIn2);

Input Arguments

collapse all

Simulation input to specify initial state, specified as a Simulink.SimulationInput object.

Initial state or operating point, specified as a Simulink.op.ModelOperatingPoint object, a Simulink.SimulationData.Dataset object, or a structure that matches the Structure or Structure with Time logging format.

Version History

Introduced in R2017a