MATLAB Object-Oriented Programming

(Joyce) #1
Data property to specify the class as double, MATLAB converts the char vector to a
double array.

properties
Data double {mustBeNumeric, mustBeFinite}
end

The assignment to the char vector does not produce an error because MATLAB converts
the char vector to class double.

a.Data = 'cubic'

a =

ValidatorFunction with properties:

Data: [99 117 98 105 99]
Interp: 'linear'

Assignment to the Interp property requires an exact match.

a = ValidatorFunction;
a.Interp = 'cu'

Error setting property 'Interp' of class 'ValidatorFunction':
Value must be a member of this set
linear
cubic
spline

Using an enumeration class provides inexact matching and case insensitivity.

Enumeration Class for Inexact Matching

Property validation using an enumeration class provides these advantages:


  • Inexact, case-insensitive matching for unambiguous char vectors or string scalars

  • Conversion of inexact matches to correct values


For example, suppose that you define the InterpMethod enumeration class for the
Interp property validation.

classdef InterpMethod
enumeration
linear

8 Properties — Storing Class Data

Free download pdf