defining a list of class instances
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hey all,
i am going to define a class in Matlab called "Node" which is sopposed to be a node of a tree stucture.
i have a variable inside it called "NodeList" which is sopposed 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 wether 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.
and third, how can i nest a list of instances of the very class inside itself?
your help and comments are highly appreciated.
0 Kommentare
Antworten (1)
David Hill
am 29 Sep. 2022
classdef Node
properties
Title
NodeType
NodeList
RelationType
ImportanceFactor
NodeIndex
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
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!