Main Content

Customize MATLAB System Block Dialog

This example shows how to customize the MATLAB System block dialog. The model contains a MATLAB System block that implements the System object™ CustomDialog. To create MATLAB System block dialog check boxes, lists, groups, tabs, and buttons, use the block dialog to modify System object properties.

System Objects

System objects allow you to implement algorithms using MATLAB®. System objects are a specialized kind of MATLAB object, designed specifically for implementing and simulating dynamic systems with inputs that change over time.

After you define a System object, you can include it in a Simulink® model using a MATLAB System block.

System Object Class Definition

You can access MATLAB source code used by the MATLAB System block by clicking the "Source Code" hyperlink from the block dialog. The System object CustomDialog implements the getPropertyGroupsImpl and getHeaderImpl methods that are used to customize the appearance of the block dialog and organize the System object properties.

  1. PropertyDefault - Property with no customization

  2. PropertyCustomPrompt - Property with custom prompt

  3. PropertyEnum - Enumeration property with a finite list of options

  4. PropertyLogical - Property validation with logical to create check box

  5. PropertyInDifferentTab - Property shown on a different tab of the dialog box

The getPropertyGroupsImpl method uses the matlab.system.display.Section and matlab.system.display.SectionGroup classes to create property sections and tabs in the dialog box. getPropertyGroupsImpl also creates a button in the "Group 2" section which calls the visualize method of the System object.

classdef CustomDialog < matlab.System
% CustomDialog Customize System block dialog

    properties
        PropertyDefault = 10
        % For PropertyDefault, with no comment above, property name is used
        % as prompt

        % PropertyCustomPrompt Use comment above property for custom prompt
        PropertyCustomPrompt = 20
        
        % PropertyEnum Use enumeration to limit values to finite list
        PropertyEnum (1,1) ColorValues = ColorValues.blue

        % PropertyInDifferentTab Use getPropertyGroupsImpl to create tabs
        PropertyInDifferentTab = 30
    end
    
    properties(Nontunable)
        % PropertyLogical Use logical property validation to create a checkbox
        PropertyLogical (1,1) logical = true
    end
    
    methods(Access = protected)
        function y = stepImpl(~, u)
            y = u;
        end
    end
    
    methods (Static, Access = protected)
        function groups = getPropertyGroupsImpl
        % Use getPropertyGroupsImpl to create property sections in the
        % dialog. Create two sections with titles "Group1" and
        % "Group2". "Group1" contains PropertyDefault and
        % PropertyCustomPrompt. "Group2" contains PropertyEnum, 
        % PropertyLogical, and a Visualize button.
            group1 = matlab.system.display.Section(...
                'Title','Group 1',...
                'PropertyList',{'PropertyDefault','PropertyCustomPrompt'});
 
            group2 = matlab.system.display.Section(...
                'Title','Group 2',...
                'PropertyList',{'PropertyEnum','PropertyLogical'});

            % Add a button that calls back into the visualize method
            group2.Actions = matlab.system.display.Action(@(actionData,obj)...
                    visualize(obj,actionData),'Label','Visualize');

            tab1 = matlab.system.display.SectionGroup(...
                    'Title', 'Tab 1', ...
                    'Sections',  [group1, group2]);
           
            tab2 = matlab.system.display.SectionGroup(...
                    'Title', 'Tab 2', ...
                    'PropertyList',  {'PropertyInDifferentTab'});

            groups = [tab1, tab2];
        end
        
        function header = getHeaderImpl
           header = matlab.system.display.Header(mfilename('class'), ...
                   'Title','AlternativeTitle',...
                   'Text','Customize dialog header using getHeaderImpl method.');
         end
    end

    methods
        function visualize(obj, actionData)
            % Use actionData to store custom data
            f = actionData.UserData;
            if isempty(f) || ~ishandle(f)
                f = figure;
                actionData.UserData = f;
            else
                figure(f); % Make figure current
            end
        
            d = 1:obj.PropertyCustomPrompt;
            plot(d);
        end
    end
end

See Also

Related Topics