Using Simulink Previous page   Next Page

Watching Function Variables During Simulation

While you are simulating the function of an Embedded MATLAB Function block, you can use several tools to keep track of variable values in the function. These tools are described in the topics that follow.

Watching with the Interactive Display

To display the value of a variable in the function of an Embedded MATLAB Function block during simulation, in the Embedded MATLAB Editor, place the mouse cursor over the variable text and observe the pop-up display. For example, to watch the variable len during simulation, place the mouse cursor over the text len in line 6 for at least a second. The value of len appears adjacent to the cursor, as shown:

  1. You can display the value for any variable in the Embedded MATLAB function in this way, no matter where it appears in the function.

Watching with the Command Line Debugger

You can report the values for an Embedded MATLAB function variable with the Command Line Debugger utility in the MATLAB window during simulation. When you reach a breakpoint, press Enter in the MATLAB window and the Command Line Debugger prompt, debug>>, appears. At this prompt, you can see the value of a variable defined for the Embedded MATLAB Function block by entering its name:

The Command Line Debugger also provides the following commands during simulation

Command
Description
dbstep
Advance to next program step after a breakpoint is encountered.
dbcont
Continue execution to next breakpoint.
dbquit
Stop simulation of the model. Press Enter after this command to return the MATLAB prompt.
help
Display help for command line debugging.
print x
Display the value of the variable x. If x is a vector or matrix, you can also index into x. For example, x(1,2).
save
Saves all variables to the specified file. Follows the syntax of the MATLAB save command. To retrieve variables to the MATLAB base workspace, use load command after simulation has been ended.
whos
Display the size and class (type) of all variables in the scope of the halted Embedded MATLAB Function block.
:

You can issue any other MATLAB command at the debug>> prompt, but the results are executed in the workspace of the Embedded MATLAB Function block. To issue a command in the MATLAB base workspace at the debug>> prompt, use the evalin command with the first argument 'base' followed by the second argument command string, for example, evalin('base','whos'). To return to the MATLAB base workspace, use the dbquit command.

Watching with MATLAB

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.


Previous page  Debugging the Function in Simulation The Embedded MATLAB Function Editor Next page

© 1994-2005 The MathWorks, Inc.