defining a list of class instances
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
David Hill
2022 年 9 月 29 日
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
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!