Mutable and Immutable Properties - MATLAB & Simulink (original) (raw)

Main Content

Set Access to Property Values

The property SetAccess attribute enables you to determine under what conditions code can modify object property values. There are four levels of set access that provide varying degrees of access to object property values:

For related information, see Properties Containing Objects.

Define Immutable Property

In this class definition, only the Immute class constructor can set the value of the CurrentDate property:

classdef Immute properties (SetAccess = immutable) CurrentDate end methods function obj = Immute obj.CurrentDate = datetime("today"); end end end

a =

Immute with properties:

CurrentDate: 09-Jun-2022

See Also

Topics