setPreSimFcn - Specify MATLAB function to run before start of each simulation on

        Simulink.SimulationInput object - MATLAB ([original](https://www.mathworks.com/help/simulink/slref/simulink.simulationinput.setpresimfcn.html)) ([raw](?raw))

Main Content

Specify MATLAB function to run before start of each simulation onSimulink.SimulationInput object

Syntax

Description

simIn = setPreSimFcn([simIn](#mw%5F3c458130-fc06-4624-bafc-d58b378963b5),[func](#mw%5F6f2df6bb-63b4-4185-a3f6-f6a739723735)) registers the callback function associated with the function handlefunc before each simulation starts. The Simulink.SimulationInput object is passed as an argument to this function.func is any MATLABĀ® function and can be used to modify the Simulink.SimulationInput object. If you use func to modify the Simulink.SimulationInput object, you must return the Simulink.SimulationInput object as the only output argument.

Input Arguments

collapse all

Simulation inputs and configuration, specified as aSimulink.SimulationInput object.

Function to run before each simulation, specified as a function handle or a function name. setPreSimFcn passes theSimulink.SimulationInput object in the shape ofx argument. The value of func has to be aSimulink.SimulationInput object to be used in a simulation. For example:

simIn = setPreSimFcn(simIn,@myPreSim)

In this example, myPreSim is a MATLAB function.

% The function can change the contents of the simulation input before parsim runs the simulation. function newSimIn = myPreSim(simIn); % Start by preserving the information already in the simulation input.
newSimIn = simIn; % Add a new model parameter to your simulation input in the preSimFcn. newSimIn = newSimIn.setModelParameter("myParameter","StopTime","10"); end

You can also specify the pre-simulation function as a function handle with additional inputs.

% The function can change the contents of the simulation input before parsim runs the simulation. function newSimIn = myPreSim_additionalArgs(simIn,additionalArg1,additionalArg2) % Start by preserving the information already in the simulation input. newSimIn = simIn; % Add a new model parameter to simIn as an additional argument. newSimIn = newSimIn.setModelParameter("StopTime",additionalArg1); end

Output Arguments

Version History

Introduced in R2017a