Basic MATLAB, Simulink, and Stateflow

Simulation performance and accuracy within MATLAB , Simulink , and Stateflow software can be affected by many things, including the model design and choice of configuration parameters. The MATLAB, Simulink, and Stateflow solvers handle most model simulations accurately and efficiently using their default parameter values. However, some models yield better results if you adjust the solver's parameters. Also, providing information about your model's behavior to the solver can improve your simulation results.
Slow simulation speed in MATLAB, Simulink, or Stateflow software can have many causes. A few of these follow. First, your model includes a MATLAB Fcn block. When a model includes a MATLAB Fcn block, the MATLAB interpreter is called at each time step, drastically slowing down the simulation. To improve the speed of your simulation, use a built-in MATLAB Fcn block or Math Function block whenever possible. Your simulations can also be slowed if your model includes an M-file S-Function. M-file S-Functions also cause the MATLAB interpreter to be called at each time step. Consider either converting the S-Function to a subsystem or to a C-MEX file S-Function. Another thing that can slow your model is if it includes a Memory block. Using a Memory block causes the variable-order solvers ( odel5s and ode113) to be reset back to order 1 at each time step.
Do not set the maximum step size to...