MATLAB Object-Oriented Programming

(Joyce) #1

Label(1,:)
end
end


a = ValidateProps;
a.Label = 'Click to Start'


a =


ValidateProps with properties:


Label: 'Click to Start'


Assignment to a property that defines size validation follows the same rules as the
equivalent indexed array assignment. For information on indexing behavior of
multidimensional arrays, see “Compatible Array Sizes for Basic Operations”.


Property Class Validation


Defining the class of a property can reduce the need to test the values assigned to the
property in your code. Any value assigned to the property must be of the specified class
or convertible to the specified class.


You can specify only one class per property. Use validation functions like mustBeNumeric
or mustBeInteger to restrict properties to a broader category of classes. For more
information on validation functions, see “Property Validation Functions” on page 8-40.


You can use any MATLAB class or externally defined class that is supported by MATLAB,
except Java and COM classes.


Place the name of the class in the property definition block following the property name
and optional size specification.


classdef MyClass
properties
Prop ClassName = defaultValue
end
end


If you do not specify a default value, MATLAB assigns an empty object of the specified
class to the property. If you define a size and a class, MATLAB attempts to create a default
value for the property that satisfies both the size and class requirement.


Property Class and Size Validation
Free download pdf