| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
| On this page… |
|---|
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.
The viewer comprises an Error Summary pane and an Error Message 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.
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.
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.
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:
Display the contents of a text string
Include hyperlinks to an object
Link to an HTML file
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.

To include a hyperlink to a block, file, or directory in the error message, include the path to the item enclosed in quotation marks.
error ('Error evaluating parameter in block "mymodel/Mu"')
displays a text hyperlink to the block Mu in the model "mymodel". Clicking the hyperlink displays the block in the model window.
error ('Error reading data from "c:/work/test.data"')
displays a text hyperlink to the file test.data in the error message. Clicking the link displays the file in your preferred MATLAB editor.
error ('Could not find data in directory "c:/work"')
displays a text hyperlink to the c:/work directory. Clicking the link opens a system command window (shell) and sets its working directory to c:/work.
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.

![]() | Saving and Restoring the Simulation State as the SimState | Running a Simulation Programmatically | ![]() |

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 |