I am going to define a class in MATLAB called "Node" which is supposed to be a node of a tree structure.
I have a variable inside it called "NodeList" which is supposed to be a list of sub nodes.
Here is what I have defined:
classdef Node
properties
Title string %name
NodeType Type_Node %enum Design/Variation
NodeList cell{Node} %list of sub nodes
RelationType Relation %enum AND/OR
ImportanceFactor float %float [0 1]
NodeIndex {mustBePositive} %int for drawing the tree
end
methods
function obj=Node(title,nodetype,nodelist,relation,impactfactor,nodeindex)
obj.Title=title;
obj.NodeType=nodetype;
obj.NodeList=nodelist;
obj.RelationType=relation;
obj.ImportanceFactor=impactfactor;
obj.NodeIndex=nodeindex;
end
end
end
While instantiating the class I am getting this error message:
Error setting default value of property 'NodeList' of class 'Node'. The 'Node' class
definition uses an instance of itself directly
or indirectly as the default value for the 'NodeList' property. This is not allowed.
First, please let me know whether the syntax I have used to define the class is correct or not.
Then, I would appreciate any suggestions to make list of instances of a class.
Third, how can I nest a list of instances of the very class inside itself?