The Test
class has been defined as a value-class as opposed to a handle class. Effectively, when you call a.change_var
, a
is passed in by-value. To store the change to the some_var
property do this:
>> a = Test;
>> a = a.change_var(2);
The alternative is to make Test
a handle class in which case the example in your question would work as you expected. To do this, inherit from the handle
class by changing the first line of your class definition to this:
classdef Test < handle