This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

setPreSimFcn

Specify a MATLAB function to run before start of each simulation through SimulationInput object, in

Syntax

in = in.setPreSimFcn(@(x) myfunction(arg1, arg2 ...))

Description

example

in = in.setPreSimFcn(@(x) myfunction(arg1, arg2 ...)) runs before each simulation starts. The Simulink.SimulationInput object is passed as an argument x to this function. myfunction is any MATLAB® function and can be used to modify the Simulink.SimulationInput object. If you use myfunction to modify the Simulink.SimulationInput object, you must return Simulink.SimulationInput object as the only output argument.

Examples

collapse all

This example shows how to specify a MATLAB function through SimulationInput object to run at before start of each simulation.

Create a PreSimFcn function.

function presim(in)
signalbuilder('sf_car/User Inputs', 'ActiveGroup', in.Variables.Value)
end

Open the model.

model = 'sf_car';
open_system(model);

Create an array of SimulationInput objects for this model. Use in.setPreSimFcn to run presim before simulation.

 n = 4;
   for idx = n:-1:1
      in(idx) = Simulink.SimulationInput(model);
      in(idx) = in(idx).setVariable('SigIndex', idx);
      in(idx) = in(idx).setPreSimFcn(@(x) presim(x));
   end

Simulate the model.

out = sim(in)

Input Arguments

collapse all

This is an input to myfunction in which you can modify the Simulink.SimulationInput object.

Arguments specified to pass to the setPreSimFcn.

Introduced in R2017a