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.


Specify a MATLAB function to run after each simulation is complete through SimulationInput object, in


in = in.setPostSimFcn(@(y) myfunction(arg1, arg2 ...))



in = in.setPostSimFcn(@(y) myfunction(arg1, arg2 ...)) runs after each simulation is complete. The Simulink.SimulationOutput object is passed as the argument y to this function. myfunction is 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 the Simulink.SimulationOutput output to replace the usual logged data or add new data to the Simulink.SimulationOutput object.


collapse all

This example specifies a MATLAB Function through SimulationInput object to run after each simulation is complete.

Create a PostSimFcn to get the mean of the output.

function newout = postsim(out);
newout.mean = mean(out.yout);

Create a SimulationInput object 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


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

Input Arguments

collapse all

This is a Simulink.SimulationOutput object which is an input to myfunction.

Arguments specified to pass to the setPostSimFcn.

Introduced in R2017a