MATLAB: Is the Embedded MATLAB Block evaluated multiple times per time step in Simulink 7.6 (R2010b)

fixedmajorminormultipleode3simulinkstepsteps;timetimes

I am running a Simulink model with a fixed-step continuous solver and I see that my Embedded MATLAB Block is executed multiple times per time step. For example if I use the ODE3 solver, the block is executed 3 times per time step. How do I set the block to execute only once per time step?

Best Answer

Except for ODE1, the fixed-step continuous solvers use multiple minor time steps to solve the differential equations for the major time steps. If you want an Embedded MATLAB Block to only run at the major time steps you can set the Sample Time accordingly in the Ports and Data Manager:
- Open the Embedded MATLAB Editor for the block you want to run on the major time steps
- Choose Tools -> Edit Data/Ports
- Set the update method to "Discrete" and specify the Sample Time as the Sample Time of the Simulink model.
You may want to create a variable in the Workspace to set both the Sample Time of the block and the model at the same time.