I am trying to understand a little bit more about Matlab classes and their properties. Here is a test class I have created:
classdef Test
properties
% Properties of the network type
some_var
end
methods
function N = Test()
end
function change_var( N, val )
N.some_var=val;
end
end
end
Now, I create an instance of this class, and call “change_var()”…
>> a=Test;
>> a.change_var(2);
>> a.some_var
ans =
[]
Why has the property “some_var” not taken on the value “val” in the assignment?
The
Testclass has been defined as a value-class as opposed to a handle class. Effectively, when you calla.change_var,ais passed in by-value. To store the change to thesome_varproperty do this:The alternative is to make
Testa handle class in which case the example in your question would work as you expected. To do this, inherit from thehandleclass by changing the first line of your class definition to this: