After asking my previous question I have come to a situation where I use a couple of object classes stored in each other's properties to retain access to several fields and methods. For example
classdef Class1
properties
Class1Prop % A property accessible from Class1
Class2 % A cell array of class 2 objects
end
methods
% Construct the class with all of its properties
function self = Class1()
end
function Class1Method
self.Class1Prop = ...
end
end
end
I populate an object of Class1 that contains a cell array of Class2. Now I would like to have methods change the values of properties inside of this object. i.e.
Class1{index}.Class2{index}.Class2Method
Will perform some computation and now have that value stored somewhere in that instance of the class.
As stated in the matlab documentation:
"If a function modifies a handle object passed as an input argument, the modification affects the object referenced by both the original and copied handles."
To gain the functionality I want, I have to use value classes (with methods that return the class object) so that the value returned by the method call is changed. The value returned can be assigned as well:
Class1{index}.Class2{index} = Class1{index}.Class2{index}.Class2Method
However, ideally
Class1{index}.Class2{index}.Class2Method
would update the Class2 properties. And that is the functionality I want. Is this possible?