Main Content

Customize Diagnostic Messages

Diagnostic Viewer displays the diagnostic messages generated during the run-time operations of Simulink® models. You can customize the error messages by using MATLAB® error functions in callbacks, S-functions, or MATLAB Function blocks.

Display Custom Text

This example shows how you can customize an error message using a MATLAB Function block.

  1. Consider a model having Constant, MATLAB Function, and Display blocks.

    Simulink model using a MATLAB Function block.

  2. In the MATLAB Function Block Editor, create a function named check_signal to display the custom message Signal is negative, when the input to the MATLAB Function block is negative.

    function y = check_signal(x)
    	if x < 0 
    		error('Signal is negative');
    	else
    		y = x;
    	end
    
  3. Simulate the model.

  4. When the input to the MATLAB Function block is negative, the Diagnostic Viewer displays the custom error message.

Diagnostic Viewer displaying the custom error message.

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 messageHyperlink
error('Error reading data from "C:/Work/designData.mat"')Opens designData.data in the MATLAB Editor.
error('Could not find data in folder "C:/Work"')Opens a Command Window and sets C:\Work as the working folder.
error('Error evaluating parameter in block "myModel/Mu"')Displays the block Mu in model myModel.

Create Programmatic Hyperlinks

This example shows how you can customize the function check_signal of a MATLAB Function block to display a hyperlink to the documentation for find_system function.

  1. Consider a model having Constant, MATLAB Function, and Display blocks.

    Simulink model using a MATLAB Function block.

  2. In the MATLAB Function Block Editor, create a function check_signal to display a hyperlink to the documentation for find_system function, when the input to the MATLAB Function block is negative.

    function y = check_signal(x)
    	if x < 0
    		error('See help for ...
                  <a href="matlab:doc find_system">find_system</a>');
    	else
    		y = x;
    	end
    
  3. Simulate the model.

  4. When the input of MATLAB Function block is negative, the Diagnostic Viewer displays the custom message with hyperlink.

    Diagnostic Viewer window displaying the custom error message with hyperlink.

See Also

Tools

Topics