Main Content


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


simIn = setPreSimFcn(simIn,func) registers the callback function associated with the function handle func 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 a Simulink.SimulationInput object.

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

simIn = setPreSimFcn(simIn,@myfunc,x)
where myfunc is a MATLAB function such as
function f = myfunc(x)
f ...%Compute function value with x as an input argument
You can also specify the presimulation function as a function handle for an anonymous function
simIn = setPreSimFcn(simIn,@(x) myfunction(arg1, arg2 ...))

Output Arguments

collapse all

Simulation configuration with presimulation function added, returned as a Simulink.SimulationInput object.

Version History

Introduced in R2017a