MatLab classes using other classes
4 ビュー (過去 30 日間)
古いコメントを表示
I’m new to using MatLabs oop and I got a simple tree structure going right now.
classdef TreeStructure < handle
%TREESTRUCTURE Summary of this class goes here
% Detailed explanation goes here
properties (SetAccess = private)
mModelName = '';
mParent = [ ];
mChildren = { };
end
methods
function obj = TreeStructure(ModelName, Parent)
if nargin == 0
else
obj.mModelName = ModelName;
obj.mParent = Parent;
end
end
function [obj ID] = addnode(obj, Parent, ChildsName)
obj.mChildren = [obj.mChildren ChildsName];
obj.mParent = [obj.mParent Parent];
ID = numel(obj.mChildren);
End
end
end
You can call it like:
tree = TreeStructure('Top', 0);
[tree ID] = addnode(tree, 0, 'obj1');
[tree ID] = addnode(tree, ID, 'obj2');
[tree ID] = addnode(tree, 1, 'obj3');
[tree ID] = addnode(tree, ID, 'obj4');
I have some other functions that’ll parse the tree and it does what I want, but I want to add some features to it. Right now when you run the last thing you get a result that looks like:
Properties:
mSubsystemName: 'Top'
mCurrentPath: ''
mParent: [0 0 1 1 3]
mChildren: {'obj1' 'obj2' 'obj3' 'obj4'}
I’m going to be using this on Simulink models and I’m going to want more info than the subsystems name. I want to create another class, let’s call it node, that’ll contain more info on the contents of the subsystem. Is it possible to have a structure or cell of another class? I’d like mChildren to contain node classes that are filled with things we decide to fill it with.
I seen that you can call other classes from within a class, the bank account demo, but I never seen them used as data types(I think that’s what I mean).
0 件のコメント
採用された回答
per isakson
2012 年 10 月 4 日
編集済み: per isakson
2012 年 10 月 4 日
Yes, instances of other classes may be values of properties.
obj.my_property = [ OtherClass, OtherClass ];
creates an array of instances of OtherClass.
.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!