Suppose I have two handle classes, 'super' and 'sub', defined as follows.
'super' is a handle class has two properties. Of these,
* 'subObject' holds an instance of 'sub' and has attributes (Access = public). * 'CellArray' is a cell array that points to the other property 'subObject' in its first element. This property has attributes (SetAccess = private, GetAccess = public).classdef super < handle properties (Access = public) subObject end properties (SetAccess = private, GetAccess = public) CellArray end methods function obj = super() obj.subObject=sub(); obj.CellArray{1}=obj.subObject; end end end
'sub' is a handle class that has one property:
* 'theString' holds a character array.classdef sub < handle properties (Access = public) theString end methods function obj = sub() obj.theString = 'MATLAB'; end end end
Finally, when I get inconsistent results with the following syntax for try to modify the value of 'CellArray' in a 'super' object:
For instance, the following syntax throws an error:
clear all;clear classes;o = super();o.CellArray{1}.theString % To check the initial property;
o.CellArray{1}.theString = 'something else'
??? Setting the 'CellArray' property of the 'super' class is not allowed. Error in ==> o.CellArray{1}.theString = 'something else'
However, when I try to do the same with the following syntax, breaking up the single line into a multipart snippet, I receive no error, but the value still changes to 'something else':
clear classes;o = super();o2 = o.CellArray{1};o2.theStringo2.theString = 'something else';
Best Answer