MATLAB Object-Oriented Programming

(Joyce) #1

Customize Property Display


In this section...
“Objective” on page 18-23
“Change the Property Order” on page 18-23
“Change the Values Displayed for Properties” on page 18-24

Objective


Change the order and number of properties displayed for an object of your class.

Change the Property Order


Suppose your class definition contains the following property definition:

properties
Name
JobTitle
Department
Salary
Password
end

In the default scalar object display, MATLAB displays all the public properties along with
their values. However, you want to display only Department, JobTitle, and Name, in
that order. You can do this by deriving from CustomDisplay and overriding the
getPropertyGroups method.

Your override


  • Defines method Access as protected to match the definition in the CustomDisplay
    superclass

  • Creates a cell array of property names in the desired order

  • Returns a PropertyGroup object constructed from the property list cell array


methods (Access = protected)
function propgrp = getPropertyGroups(~)
proplist = {'Department','JobTitle','Name'};
propgrp = matlab.mixin.util.PropertyGroup(proplist);

Customize Property Display
Free download pdf