Main Content

Customize Diagnostic Messages

TheDiagnostic Viewerdisplays the output of MATLAB®error functions executed during simulation.

You can customize simulation error messages in the following ways by using MATLAB error functions in callbacks, S-functions, orMATLAB Functionblocks.

Display Custom Text

This example shows how to can customize the MATLAB functioncheck_signalto display the textSignal is negative.

  1. Open theMATLAB Functionfor editing.

  2. In the MATLAB Editor, create a function to display custom text.

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

  3. Simulate the model.

    A runtime error appears and you are prompted to start the debugger. ClickOK.

  4. To view the following error inDiagnostic Viewer, close the debugger.

Create Hyperlinks to Files, Folders, or Blocks

To create hyperlinks to files, folders, or blocks in an error message, include the path to these items within customized text.

Example error message Hyperlink
error ('Error reading data from "C:/Work/designData.mat"') OpensdesignData.datain the MATLAB Editor.
error ('Could not find data in folder "C:/Work"') Opens a Command Window and setsC:\Workas the working folder.
error ('Error evaluating parameter in block "myModel/Mu"') Displays the blockMuin modelmyModel.

Create Programmatic Hyperlinks

This example shows how to can customize the MATLAB functioncheck_signalto display a hyperlink to the documentation forfind_system.

  1. Open theMATLAB Functionfor editing.

  2. In the MATLAB Editor, create a function to display custom text.

    function y = check_signal(x) if x < 0 error('See help for find_system'); else y = x; end

  3. Simulate the model.

    A runtime error appears and you are prompted to start the debugger. ClickOK.

  4. To view the following error inDiagnostic Viewer, close the debugger.

Related Topics