MATLAB: Is constructor method the only method that creates an object in a class definition

class object-orientedoop

Another way to ask this question is: how do I create a value class object as the output of a handle class ordinary method? For example,
classdef handleClassA < handle
properties
end
methods
function obj = handleClassA(varargin)
...
end
function ValueClassobj2 = unknownmethod(handleClassAobj, ValueClassobj1)
ValueClassobj2.property1 = ...
some_sort_function(handleClassAobj.property3, ValueClassobj1.property1);
...
end
end
end
If I do it the above way, the output is a struct with field property1, etc., not a object of a class.

Best Answer

I think you are trying to do,
function ValueClassobj2 = unknownmethod(handleClassAobj, ValueClassobj1)
ValueClassobj2 = ValueClassobj1; %clone of obj1
ValueClassobj2.property1 = ...
some_sort_function(handleClassAobj.property3, ValueClassobj1.property1);
...
end