Main Content

setPostSimFcn

Specify aMATLABfunction to run after each simulation is complete throughSimulationInputobject,in

Description

example

in = in.setPostSimFcn(func)registers the callback function associated with the function handlefuncafter each simulation is complete. TheSimulink.SimulationInputobject is passed as an argument to this function.funcis any MATLAB®function and can be used to do the post processing on the output. To return post processed data, you must return it as values in a struct. These values are then packed into theSimulink.SimulationOutputoutput to replace the usual logged data or add new data to theSimulink.SimulationOutputobject.

Examples

collapse all

This example specifies a MATLAB Function throughSimulationInputobject to run after each simulation is complete.

创建一个PostSimFcnto get the mean of the output.

functionnewout = postsim(out); newout.mean = mean(out.yout);end

创建一个SimulationInputobject for a model.

in = Simulink.SimulationInput('vdp'); in = in.setPostSimFcn(@(x) postsim(x)); in = in.setModelParameter('SaveOutput','on');

Simulate the model.

out = sim(in)

View your result

out.mean

It is best practice to avoid using'ErrorMessage'and'SimulationMetadata'as field names in the function.

Input Arguments

collapse all

Function to run after each simulation completes, specified as a function handle or a function name.setPostSimFcnpasses theSimulink.SimulationInputobject in the shape ofyargument. For example:

in = in.setPreSimFcn(@myfunc, y)
wheremyfuncis a MATLAB function such as
functionf = myfunc(x) f...%Compute function value with x as an input argument
You can also specify func as a function handle for an anonymous function:
in = in.setPostSimFcn(@(y) myfunction(arg1, arg2...))

版本History

Introduced in R2017a