Main Content

sim

Simulate Simulink model using simulation scenario

    Description

    sim_out = sim(sim_obj) simulates a Simulink® model using the simulation scenario specified in sim_obj.

    Before simulating the model, specify the parameter values and signals to log in the Parameters and LoggingInfo properties of sim_obj. The software restores the parameter values and logging settings to their original values after simulation.

    sim_out = sim(sim_obj,Name=Value) specifies simulation parameters using one or more Name=Value arguments.

    example

    Examples

    collapse all

    Simulate the sdoHydraulicCylinder model, and store the Pressures signal of the model.

    Log the Pressures signal that is output from the first port in the Cylinder Assembly block of the model.

    Pressures = Simulink.SimulationData.SignalLoggingInfo;
    Pressures.BlockPath = 'sdoHydraulicCylinder/Cylinder Assembly';
    Pressures.OutputPortIndex = 1;

    Create a simulation scenario for the model, and specify the signal to log.

    simulator = sdo.SimulationTest('sdoHydraulicCylinder');
    simulator.LoggingInfo.Signals = [Pressures];

    Specify parameter values for simulation.

    Ac = sdo.getParameterFromModel('sdoHydraulicCylinder','Ac');
    Ac.Value = 0.5;
    simulator.Parameters = Ac;

    Simulate the model.

    sim_obj = sim(simulator);

    The specified signal Pressures is logged during simulation in the LoggedData property of sim_obj. After simulation, the sim command restores model parameter and model signal logging changes. If you want to preserve your changes, specify the RestoreSettingsAfterSim argument as false.

    sim_obj = sim(simulator,'RestoreSettingsAfterSim',false);

    Input Arguments

    collapse all

    Simulation scenario for a model, specified as an sdo.SimulationTest object.

    Example: simulator

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: sim_out = sim(sim_obj,'TimeOut',20) specifies the maximum simulation run time as 20 seconds.

    You can specify any of the simulation parameters that the Simulink sim command accepts as Name,Value arguments. In addition, you can specify the following parameters.

    Treatment of warnings as errors, specified as the comma-separated pair consisting of 'ErrorOnWarnings' and true or false. When you specify ErrorOnWarning as true, the sim command treats warnings that are generated during simulation as errors.

    Data Types: logical

    Restoration of settings after simulation, specified as the comma-separated pair consisting of 'RestoreSettingsAfterSim' and one of true or false. When you specify RestoreSettingsAfterSim as true, the sim command restores model parameter and model signal logging changes after the simulation ends.

    Data Types: logical

    Operating point setup object, specified as the comma-separated pair consisting of 'OperatingPointSetup' and an sdo.OperatingPointSetup object.

    OperatingPointSetup must be specified as an sdo.OperatingPointSetup object. If provided, the steady-state operating point is computed.

    For more information about computing a steady-state operating point during model simulation, see sdo.OperatingPointSetup.

    Data Types: function_handle

    Output Arguments

    collapse all

    Simulation scenario object containing logged signal data, returned as an sdo.SimulationTest object. The logged data is stored in the LoggedData property of sim_out.

    Version History

    Introduced in R2011b