Hi Alessandro,
To copy the properties that contain handles, it is essential to create a new default object of ‘handleClass’ and then assign the property values from the current object to this new object.
In the code you provided, the line ‘eval(class(hobj))’ attempts to create a default object of class ‘handleClass’. However, an error is raised because there is no default constructor defined in ‘handleClass’. Without a default constructor, MATLAB cannot instantiate the object when no input arguments are provided.
Adding a default constructor will resolve this error by specifying how to initialize the object with default properties.
To modify the constructor of ‘handleClass’, please refer to the code given below.
function obj = handleClass(in)
if nargin==0
obj.p1=0;
else
obj.p1=in;
end
end
In the ‘handleClassHandlePropCopyable1’ class, you can create default object ‘new_hobj’ by using the constructor given above.
new_hobj = eval(class(hobj));
For more information, please refer to the MATLAB documentation given below.
Hope this solves your query.