|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.
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 Function block executes.
You can use the MATLAB error function in callbacks, S-functions or the MATLAB Function block to create custom error messages specific to your application. Capabilities available for messages include:
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 Function block invokes the following function:
function y=check_signal(x) if x<0 error('Signal is negative'); else y=x; end
Executing this model causes a runtime error and starts the debugger when you click the OK button of the runtime error message. When you quit the debugger, an error message in the Simulation Diagnostics window.
To include a hyperlink to a block, file, or folder 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 folder "c:/work"')
displays a text hyperlink to the c:/work folder. Clicking the link opens a system command window (shell) and sets its working folder 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 window displays a hyperlink labeled find_system. Clicking the link opens the documentation for the find_system command in the MATLAB Help browser.