oop - How do I create efficient instance variable mutators in Matlab? -


First, I have implemented a mutator in the following way, although it can run smoothly at the recursive OO algorithm And I suspect it could be because I was repeating the objects on every function call ... is this right?

  %% example only obj2 = tripleAllpoints (obj1) obj.pts = obj.pts * 3; Obj2 = obj1 end  

Then I tried to apply the mutator without using the output object ... However, it seems that I can not do that in MATLAB - change "stick "Due to a Scope Problem?

  %% Examples all three points (obj1) obj1.pts = obj1.pts * 3;  

For the purposes of the application, a very simplified version of my code (which uses Oo and Rickerson) is below.

  classdef myslice Number of properties% array digits NROOS% number of numbers NDIM% number of dimensions subs% sub-slides end% end properties methods calcshab obj obj.subs = cell (1 , Oz. NRO); I = 1 for: obj.nROW obj.subs {i} = myslice; Obj.subs {i} .pts = obj.pts (1: i, 2: end); End end function vol = calcvol (obj) if obj.nROW == 1 obj.volume = prod (obj.pts); And obj.volume = 0; CalcSubs (obj); For I = 1: obj.nROW obj.volume = obj.volume + calcVol (obj.subs {i}); End end end end% end methods end% end classdef  

:.

Value class is passed by value, and whenever you write it, it is copied. In addition, method calls to obj = method (obj); For change in should be in the form of 'stick'.

On the contrary, the objects are passed by the handle reference, and so, whenever you change an object in any workspace - the workspace of the base workspace or the function - the object changes everywhere In this way, Calling workspace calls method (OBJ); Regardless of change obj , however, obj has not been explicitly sent.

The default class is the value object if you want to handle items, then your classdef line should be:

  classdef myslice & lt; Handle  

i.e. You are sub-closing the handle class.


Comments