Main Content

setScenario

R2026b

Set simulation scenario for a model

Since R2026b

    Description

    simulator_out = setScenario(simulator,scenario) sets a new simulation scenario, scenario, for the sdo.SimulationTest object simulator. The scenario configures model variables using a Simulink.SimulationInput object or a function handle that returns a Simulink.SimulationInput object.

    example

    Examples

    collapse all

    This example shows how to specify scenarios for model simulation.

    Create a simulation configuration for the referenceScenarios model.

    Simulator = sdo.SimulationTest("referenceScenarios");

    Specify two simulation scenarios, using functions. The referenceScenarios_configStep function sets the value of the model variable ReferenceSelection to 1. The referenceScenarios_configSine function sets the value of the model variable ReferenceSelection to 2. To view these functions, at the command line, type:

    >> edit referenceScenarios_configStep.m
    >> edit referenceScenarios_configSine.m
    

    Specify the simulation scenario for the Simulator object as the referenceScenarios_configSine function using a function handle.

    Simulator = setScenario(Simulator,@referenceScenarios_configSine);

    Simulate the model. The model uses the value 2 for the ReferenceSelection variable during simulation.

    Simulator = sim(Simulator);

    Input Arguments

    collapse all

    Simulation configuration for a Simulink® model, specified as an sdo.SimulationTest object. A simulation configuration specifies input signals, parameter values, and initial state values, and signals to log for a model.

    New simulation scenario definition, specified as one of these:

    • A Simulink.SimulationInput object for the same model for which you created the sdo.SimulationTest object simulator. During model simulation, the software only uses the values in the Variables property of the Simulink.SimulationInput object.

    • A function handle that accepts no inputs, and returns one output as a Simulink.SimulationInput object for the same model for which you created simulator. During model simulation, the software only uses the values in the Variables property of the Simulink.SimulationInput object.

    • An empty array, []. Specifying the scenario as [] clears the existing scenario definition and resets the model variables to their original values.

    Output Arguments

    collapse all

    Updated simulation configuration using the defined simulation scenario, returned as an sdo.SimulationTest object.

    Version History

    Introduced in R2026b