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.
Consider a model having Constant, MATLAB Function, and Display blocks.
In the MATLAB Function Block Editor, create a function named
check_signal
to display the custom messageSignal 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
Simulate the model.
When the input to the MATLAB Function block is negative, the Diagnostic Viewer displays 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 message | Hyperlink |
---|---|
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.
Consider a model having Constant, MATLAB Function, and Display blocks.
In the MATLAB Function Block Editor, create a function
check_signal
to display a hyperlink to the documentation forfind_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
Simulate the model.
When the input of MATLAB Function block is negative, the Diagnostic Viewer displays the custom message with hyperlink.