Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing class methods to update properties in an object
    primarykey
    data
    text
    <p>After asking my <a href="https://stackoverflow.com/questions/8982376/interfacing-with-super-and-subclass-constructors/" title="previous question">previous question</a> 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</p> <pre><code>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 </code></pre> <p>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.</p> <pre><code> Class1{index}.Class2{index}.Class2Method </code></pre> <p>Will perform some computation <em>and</em> now have that value stored somewhere in that instance of the class.</p> <p>As stated in the matlab documentation: </p> <blockquote> <p>"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."</p> </blockquote> <p>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:</p> <pre><code>Class1{index}.Class2{index} = Class1{index}.Class2{index}.Class2Method </code></pre> <p>However, ideally </p> <pre><code>Class1{index}.Class2{index}.Class2Method </code></pre> <p>would update the Class2 properties. And <em>that</em> is the functionality I want. Is this possible?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload