This is probably a very basic question, but I did not find anything on the internet. I am writing a matlab class, which has various class properties. I am setting all of them (some with input arguments, some default). I change one class variable in another class method. This does not work (the variable gets deleted when out of the function scope). What is the best way to solve this? Put everything in the constructor?
classdef MyClass
properties
matrix1
matrix2
matrix3
end
methods
function obj = MyClass()
obj.matrix1 = zeros(2)
obj.matrix2 = ones(3)
end
function obj = func(obj)
obj.matrix2 = 3*ones(3)
end
function obj = func2(obj)
obj.matrix3 = obj.matrix2 %this does not work. matrix2 has its original value, not 3*ones(3)
end
end
end
I call it like
object = MyClass()
object.func()
object.func2()