| Stateflow User's Guide | ![]() |
Run-Time Debugging for Embedded MATLAB Functions
You use simulation to test your Embedded MATLAB functions for run-time errors that are not detectable by Stateflow diagnostics. When you start simulation of your model, Simulink performs diagnostic tests of your completed Embedded MATLAB functions for missing or undefined information and possible logical conflicts as described in Checking Embedded MATLAB Functions for Syntax Errors. If no errors are found, Stateflow begins the simulation of your model.
Use the following procedure to simulate and debug the stats Embedded MATLAB function during run-time conditions:
avg. If you click Step here, execution advances to line 8, past the execution of the subfunction avg. In order 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 pointing down under line 9, indicating the completion of the function stats.
len, place the mouse cursor over the text len in line 6 for at least a second.
len appears adjacent to the cursor as shown:
You can display the value for any data in the Embedded MATLAB block function in this way, no matter where it appears in the function. For example, you can display the values for the vector vals by placing the cursor over it as an argument to the function length in line 6, or as an argument in the function header.
You can also report the values for Embedded MATLAB block function data in the MATLAB window during simulation. When you reach a breakpoint, the DB>> command prompt appears in the MATLAB window (you might have to press Enter to see it). At this prompt you can inspect data defined for the Embedded MATLAB block by entering the name of the data as shown in the following example:
As another debugging alternative, you can display the execution result of an Embedded MATLAB function line by omitting the terminating semicolon. If you do, execution results for the line are echoed to the MATLAB window during simulation.
In the Simulink window, the computed values of mean and stdev now appear in the Display blocks.
| Checking Embedded MATLAB Functions for Syntax Errors | Model Coverage for an Embedded MATLAB Function | ![]() |
© 1994-2005 The MathWorks, Inc.