I have a handle class "SuperClass" and a class "SubClass" which derives from SuperClass, with the following definitions:
classdef SuperClass < handle properties prop1 prop2 end methods function obj = SuperClass(prop1,prop2) obj.prop1 = prop1; obj.prop2 = prop2; end endendclassdef SubClass < SuperClass properties newprop end methods function obj = SubClass(prop1,prop2,newprop) obj = obj@SuperClass(prop1,prop2); obj.newprop = newprop; end endend
I would like to aggregate objects of these classes into a single vector as follows:
supobj = SuperClass(1,2);subobj = SubClass(3,4,5);vec(1) = supobj;vec(2) = subobj;
Conceptually, this should be possible because subobj is an object of SuperClass. However, this gives me the following error:
??? The following error occurred converting from SubClass to SuperClass: Input argument "prop2" is undefined.
Best Answer