Define Your Own Custom Model Advisor Checks

To specify your own set of conditions and model configuration settings for the Model Advisor to review, create custom checks. This graphic provides an overview of the workflow for creating and defining custom checks. The sections below provide details on each workflow step.

Create the sl_customization File and Function

To define a custom check, begin by creating an sl_customization.m file on the MATLAB path. In the sl_customization.m file, create an sl_customization function. The sl_customization function accepts one argument, a customization manager object:

function sl_customization(cm)

Tip

  • You can have more than one sl_customization.m file on your MATLAB path.

  • Do not place an sl_customization.m file that customizes Model Advisor checks and folders in your root MATLAB® folder or its subfolders, except for the matlabroot/work folder. Otherwise, the Model Advisor ignores the customizations that the file specifies.

Register Custom Checks

To register custom checks, use the addModelAdvisorCheckFcn method, which is part of the customization manager object that you input to the sl_customization function. Add this code to your sl_customization.m file:

function sl_customization(cm)
% register custom checks
cm.addModelAdvisorCheckFcn(@checkDefinitionFcn)

The addModelAdvisorCheckFcn method registers the check that you define in the checkDefinitionFcn to the By Product folder of the Model Advisor. The checkDefinitionFcn argument is a handle to the function that defines the custom check that you want to add to the Model Advisor as an instance of the ModelAdvisor.Check class.

Create a Check Definition Function

The check definition function defines the actions that the Model Advisor takes when you run the check. For each check that you create, you should define a check definition function. The following sections describe the key components of the check definition function.

Create an Instance of the ModelAdvisor.Check Class

For each custom check, create one instance of the ModelAdvisor.Check class. Use the ModelAdvisor.Check properties and methods to define the check user interface and actions. This table describes some key check components.

ContentsDescription
Check ID (required)Uniquely identifies the check. The Model Advisor uses this ID to access the check.
Handle to the check callback function (required)Function that specifies the contents of a check.
Check name (recommended)Creates a name for the check that the Model Advisor displays.
Model compiling (optional)Specifies whether the model is compiled for check analysis.
Input Parameters (optional)Adds input parameters that request input from the user. The Model Advisor uses the input to perform the check.
Action (optional)Adds a fixing action.

Define Check Actions and a Fix

The check definition function contains a check callback function that specifies the actions that you want the Model Advisor to perform on a model or subsystem. Define the check callback function and pass a handle to it to the setCallbackFcn method. The Model Advisor executes the callback function when you run the check. Callback functions provide one or more return arguments that display the results after executing the check.

If you are specifying a custom check fix, the check definition function should also contain an action callback function. In the check definition function, create an instance of the ModelAdvisor.Action class. Define the action callback function and pass a handle to it to the setCallbackFcn method. When you define an action, the Model Advisor includes an Action box below the Analysis box. The Action box contains a button for fixing the model or subsystem. In the example below, the button name is Modify Settings.

Callback and action callback functions provide one or more return arguments for displaying the results after executing the check. See Create the Check Callback Definition Function and Create the Action Callback Definition Function.

Define Check Input Parameters

With input parameters, you can request input before running the check. Define input parameters using the ModelAdvisor.InputParameter class. You must include input parameter definitions inside a custom check definition function. You must define one instance of this class for each input parameter that you want to add to a Model Advisor check.

Specify the layout of input parameters with the following methods.

MethodDescription
setInputParametersLayoutGridSpecifies the size of the input parameter grid.
setRowSpanSpecifies the number of rows the parameter occupies in the input parameter layout grid.
setColSpanSpecifies the number of columns the parameter occupies in the input parameter layout grid.

The Model Advisor displays input parameters in the Input Parameters box.

Define Where Custom Checks Appear

Create a folder for custom checks in the By Product folder by using the publish method. Then use the Model Advisor Configuration Editor to customize the folders within the Model Advisor tree. For more information, see Use the Model Advisor Configuration Editor to Customize the Model Advisor.

You can customize the Model Advisor by using the ModelAdvisor.Group and ModelAdvisor.FactoryGroup classes instead of the Model Advisor Configuration Editor. However, these APIs are a less flexible and more time-consuming way of customizing the Model Advisor. To place customized checks in custom folders at the top-level of the Model Advisor tree (the Model Advisor root), use the ModelAdvisor.Group class. To place customized checks in new folders in the By Task folder, use the ModelAdvisor.FactoryGroup class. You must include methods that register these tasks and folders in the sl_customization function.

Format Check Results

To use default formatting for Model Advisor results, specify the callback function type as DetailStyle in the setCallbackFcn method. If the default formatting does not meet your needs, use one of the other callback function styles and either the ModelAdvisor.FormatTemplate class or these other Model Advisor formatting APIs:

ClassDescription
ModelAdvisor.Text

Create a Model Advisor text output.

ModelAdvisor.List

Create a list.

ModelAdvisor.Table

Create a table.

ModelAdvisor.Paragraph

Create and format a paragraph.

ModelAdvisor.LineBreak

Insert a line break.

ModelAdvisor.Image

Include an image in the Model Advisor output.

Display and Enable Checks

You can specify how a custom check appears in the Model Advisor. You can define when to display a check, or whether a user can select or clear a check using the Visible, Enable, and Value properties of the ModelAdvisor.Check class.

The following chart illustrates how the Visible, Enable, and Value properties interact.

If you add checks to the Model Advisor as tasks, specify these properties in the ModelAdvisor.Task class. If you specify the properties in both the ModelAdvisor.Check and ModelAdvisor.Task classes, the ModelAdvisor.Task properties take precedence, except for the Visible and LicenseName properties.

See Also

| | | | |

Related Topics