Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Diagnosing Simulation Errors

Response to Run-Time Errors

If errors occur during a simulation, the Simulink software halts the simulation, opens the subsystems that caused the error (if necessary), and displays the errors in the Simulation Diagnostics Viewer. The following sections explain how to use the viewer to determine the cause of the errors, and how to create custom error messages.

Simulation Diagnostics Viewer

The viewer comprises an Error Summary pane and an Error Message pane.

Error Summary Pane

The upper pane lists the errors that caused the simulation to terminate. The pane displays the following information for each error.

Message.   Message type (for example, block error, warning, or log)

Source.   Name of the model element (for example, a block) that caused the error

Reported By.   Component that reported the error (for example, the Simulink product, the Stateflow product, or the Real-Time Workshop product).

Summary.   Error message, abbreviated to fit in the column

You can remove any of these columns of information to make room for other columns. To remove a column, select the View menu and uncheck the corresponding item.

Error Message Pane

The lower pane initially contains the contents of the first error message listed in the top pane. You can display the contents of other messages by clicking their entries in the upper pane.

In addition to displaying the viewer, the Simulink software opens (if necessary) the subsystem that contains the first error source and highlights the source.

You can display the sources of other errors by clicking: anywhere in the error message in the upper pane; the name of the error source in the error message (highlighted in blue); or the Open button on the viewer.

Changing Font Size

To change the size of the font used to display errors, select Increase Font Size or Decrease Font Size from the Font Size menu of the viewer.

Creating Custom Simulation Error Messages

The Simulation Diagnostics Viewer displays the output of any instance of the MATLAB error function executed during a simulation. Such instances include those invoked by block or model callbacks, or by S-functions that you create or that the MATLAB Fcn block executes.

You can use the MATLAB error function in callbacks, S-functions or the MATLAB Fcn block to create custom error messages specific to your application. Following are the capabilities available to messages:

Displaying A Text String

To display the contents of a text string, pass the string enclosed by quotation marks to the error function.

The following example shows how you can make the user-created function check_signal display the string Signal is negative.

The MATLAB Fcn block invokes the following function:

function y=check_signal(x)
  if x<0 
    error('Signal is negative');
  else
    y=x;
  end

Executing this model displays the error message in the Simulation Diagnostics Viewer.

Creating Hyperlinks to Files, Directories, or Blocks

To include a hyperlink to a block, file, or directory in the error message, include the path to the item enclosed in quotation marks.

Creating Programmatic Hyperlinks

You can create a hyperlink that, when clicked, causes the evaluation of a MATLAB expression. For example, the following model InitFcn callback displays an error, when the model starts, with a hyperlink to help for the find_system command.

error('See help for the <a href="matlab:doc find_system">find_system</a>

In this example, the Simulation Diagnostics Viewer displays a hyperlink labeled find_system. Clicking the link opens the documentation for the find_system command in the MATLAB Help browser.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS