MATLAB: Does passing data to an Embedded MATLAB block through it’s argument list slow down the simulation in Simulink 7.3 (R2009a)

simulinkslowerslownessspeed

I have two similar models implementing the same amount of computation but taking different amounts of time to simulate. The models use an EML block to perform most of the calculations on a given set of data. The difference lies in the way large matrices are passed into the EML block. The two methods are:
a) Load data within Embedded MATLAB function block using LOAD declared as extrinsic.
b) Load data in MATLAB base workspace and then pass it on to the Embedded MATLAB Function block through its argument list as a parameter.
The simulation speed is slower when data is read from the MATLAB base workspace and passed into the EML block as an argument.
a) The elapsed time is 11.531966 seconds when running txad1.mdl
b) The elapsed time is 128.039013 seconds when running txad1_m.mdl
The degradation of simulation time is almost a factor of 10.

Best Answer

The slow simulation speed is due to data validity checking which is enabled by default.
To work around this, disable debugging for the Embedded MATLAB block. You can do so by using the Debug dropdown menu in the Embedded MATLAB editor and uncheck the "Enable Debugging" option.