Main Content

getPropertyGroups

Class: matlab.mixin.CustomDisplay
Namespace: matlab.mixin

Construct array of customized property groups

Syntax

groups = getPropertyGroups(obj)

Description

groups = getPropertyGroups(obj) returns a 1-by-N array of matlab.mixin.util.PropertyGroup objects, where N is the number of groups. MATLAB® displays property groups separated by blank spaces. Each default display state handler method calls this method once. Override this method to construct one or more customized groups of properties to display.

The default implementation returns the properties in one group. These properties must have public GetAccess and must not be defined as Hidden. If the object is scalar, MATLAB includes dynamic properties.

Each group object array has these fields:

  • Title — Text used as the header for the property group or an empty string if no title is used.

  • PropertyList — The property list can be either:

    • A 1-by-1 struct of property names and corresponding values

    • A cell array of property names

Use the struct if the object is scalar and you want to assign custom property values. Otherwise, use a cell array of property names. If the object is scalar, MATLAB adds the property values retrieved from the object.

Input Arguments

expand all

Object array to apply customized property group format to. The class of obj must be derived from matlab.mixin.CustomDisplay.

Output Arguments

expand all

Array of 1-by-N matlab.mixin.util.PropertyGroup objects, where N is the number of groups.

Attributes

Accessprotected

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Create two property groups for class display.

The EmployeeInfo class has five properties describing an employee. Define a getPropertyGroups method that, for scalar objects, defines two PropertyGroup objects. The method returns two property groups with the titles Employee Bio and Contact Info.

classdef EmployeeInfo < matlab.mixin.CustomDisplay
    properties
        Name = "Alex Doe"
        Department = "Development"
        JobTitle = "Engineer"
        Email = "alexdoe@notacompany.org"
        Phone = "(555) 555-555"
    end

    methods (Access = protected)
        function propgrp = getPropertyGroups(obj)
            if ~isscalar(obj)
                propgrp = getPropertyGroups@matlab.mixin.CustomDisplay(obj);
            else
                bioList = ["Name","Department","JobTitle"];
                bioTitle = "Employee Bio";
                bioGrp = matlab.mixin.util.PropertyGroup(bioList,bioTitle);
                contactList = ["Email","Phone"];
                contactTitle = "Contact Info";
                contactGrp = matlab.mixin.util.PropertyGroup(contactList,contactTitle);
                propgrp = [bioGrp,contactGrp];
            end
        end
    end
end

Create a scalar instance to see how the properties are displayed.

a = EmployeeInfo
a = 

  EmployeeInfo with properties:

   Employee Bio
          Name: "Alex Doe"
    Department: "Development"
      JobTitle: "Engineer"

   Contact Info
         Email: "alexdoe@notacompany.org"
         Phone: "(555) 555-555"

Version History

Introduced in R2013b