MATLAB Object-Oriented Programming

(Joyce) #1
set(H,'PropertyName',PropertyValue)

You can pass a cell array of property names and a cell array of property values to set:

props = {'PropertyName1','PropertyName2'};
vals = {Property1Value,Property2Value};
set(H,props,vals)

If length(H) is greater than one, then the property value cell array (vals) can have
values for each property in each object. For example, suppose length(H) is 2 (two object
handles). You want to assign two property values on each object:
props = {'PropertyName1','PropertyName2'};
vals = {Property11Value,Property12Value;Property21Value,Property22Value};
set(H,props,vals))

The preceding statement is equivalent to the follow two statements:
set(H(1),'PropertyName1',Property11Value,'PropertyName2',Property12Value)
set(H(2),'PropertyName1',Property21Value,'PropertyName2',Property22Value)

If you specify a scalar handle, but no property names, set returns a struct with one
field for each property in the class of H. Each field contains an empty cell array.

SV = set(h);

Class Derived from matlab.mixin.SetGet


This sample class defines a set/get interface and illustrates the behavior of the inherited
methods:

classdef LineType < matlab.mixin.SetGet
properties
Style = '-'
Marker = 'o'
end
properties (SetAccess = protected)
Units = 'points'
end
methods
function obj = LineType(s,m)
if nargin > 0
obj.Style = s;
obj.Marker = m;
end

7 Value or Handle Class — Which to Use

Free download pdf