| Using Simulink | ![]() |
Debugging the Function in Simulation
You can debug your Embedded MATLAB Function block just like you can debug a function in MATLAB. In simulation, you test your Embedded MATLAB functions for run-time errors with tools similar to the MATLAB debugging tools.
When you start simulation of your model, Simulink checks to see if the Embedded MATLAB Function block has been built since creation, or since a change has been made to the block. If not, it performs the build described in Checking the Function for Errors. If no diagnostic errors are found, Simulink begins the simulation of your model.
Use the following procedure to debug the stats Embedded MATLAB function during simulation of the model:
call_stats_block2 model that you save at the end of Programming the Embedded MATLAB Function, and double-click its Embedded MATLAB Function block stats to open it for editing in the Embedded MATLAB Editor.
-) character.
stats.
You can also step execution by entering dbstep at the Command Line Debugger. See Watching with the Command Line Debugger for a description of the Command Line Debugger in MATLAB.
Notice that line 7 calls the subfunction avg. If you click Step here, execution advances to line 8, past the execution of the subfunction avg. To track execution of the lines in the subfunction avg, you need to click the Step In tool.
avg, as shown.
avg finishes its execution, and you see a green arrow pointing down under its last line as shown.
In the Embedded MATLAB Editor, a green arrow points down under line 9, indicating the completion of the function stats.
You can also continue execution by entering dbcont at the Command Line Debugger. See Watching with the Command Line Debugger for a description of the Command Line Debugger in MATLAB.
In the Simulink window, the computed values of mean and stdev now appear in the Display blocks.
| Debugging an Embedded MATLAB Function | Watching Function Variables During Simulation | ![]() |
© 1994-2005 The MathWorks, Inc.