Main Content

matlab.mixin.SetGet Class

Namespace: matlab.mixin

Provide handle classes with set and get methods

Description

Use the matlab.mixin.SetGet class to derive classes that inherit a set and get method interface. These methods provide functionality similar to the set and get functions.

The set and get methods inherited from matlab.mixin.SetGet support inexact property name matching. You can use a combination of partial and case-insensitive names as long as the inexact name is not ambiguous.

In contrast, dot-based property references require exact property name matches. To implement exact name matching with set and get methods, use the matlab.mixin.SetGetExactNames class.

All classes derived from matlab.mixin.SetGet are handle classes.

The matlab.mixin.SetGet class is a handle class.

Class Attributes

Abstract
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Methods

expand all

Examples

collapse all

Define a class that derives from matlab.mixin.SetGet and has two properties

classdef PropSetGet < matlab.mixin.SetGet
    properties
       Number {mustBeNumeric} 
       Str string
    end
end

Create an instance of the class and use the inherited set method to set a property value.

p = PropSetGet;
set(p,'Number',8)

Get the value of the Number property using the inherited get method.

get(p,'Number')
ans =

     8

Establish a priority for partial name matching using the PartialMatchPriority property attribute. The default priority, PartialMatchPriority = 1, is the highest priority. The greater the value of PartialMatchPriority, the lower the relative priority applied when resolving potentially ambiguous inexact property names.

Derive a class from matlab.mixin.SetGet and set the priority of the DistanceFromSun property lower for partial name matching.

classdef PlanetSize < matlab.mixin.SetGet
    properties
        Diameter
        EarthMass
    end
    properties(PartialMatchPriority = 2)
        DistanceFromSun
    end
end

Create an object and set the Diameter property using the partial name Di.

p = PlanetSize;
set(p,'Di',6792)
disp(p)
  PlanetSize with properties:

           Diameter: 6792
          EarthMass: []
    DistanceFromSun: []

Version History

Introduced in R2014b