implementation of subclass from triangulation
古いコメントを表示
Hi everyone,
I am trying to implement a derived class from the 'triangulation' class available in Matlab 2014. The aim is to introduce additional properties and methods. I tried to mimic the example available in the Matlab documentation, but I failed even in creating a simple constructor. The minimal example is the following
classdef mymesh < triangulation
properties
Obj = [];
end
methods
% constructor
function primal = mymesh(P,T,M) % M is the object code
primal = primal@triangulation(T,P);
primal.Obj = M;
end
end
end
But trying to call it with the code
P = [0 0 0; 0 1 0; 1 1 0; 1 1 1];
T = [1 2 3 4];
M = ones(size(T,1),1);
c = mymesh(P,T,M);
makes Matlab crash. Can anyone point my were I am wrong?
Thank you in advance
Fabio
1 件のコメント
Fabio Freschi
2016 年 1 月 19 日
採用された回答
その他の回答 (2 件)
Rebecca Krosnick
2016 年 1 月 20 日
0 投票
It seems that we cannot create a subclass of "triangulation". Instead, you can create a class that has a "triangulation" object as a property rather than creating a subclass of "triangulation".
2 件のコメント
Fabio Freschi
2016 年 1 月 20 日
Tom Clark
2016 年 7 月 6 日
Yes it will. I've extended Rebecca's answer below to address this with a full example.
per isakson
2016 年 1 月 21 日
編集済み: per isakson
2016 年 1 月 21 日
You are too kind to Matlab. Matlab shall not crash whether or not you make a mistake. Now I crashed R2013b a couple of time with your code. I assume you need to ask support.
However, you might want to try this
P = [0 0 0; 0 1 0; 1 1 0; 1 1 1];
T = [1 2 3 4];
M = ones(size(T,1),1);
tr = triangulation(T,P);
mym = mymesh(tr,M);
mym.TR.Points
outputs
ans =
0 0 0
0 1 0
1 1 0
1 1 1
where
classdef mymesh < handle
properties
Obj = [];
TR
end
methods
% constructor
function primal = mymesh( tr, M ) % M is the object code
primal.Obj = M;
primal.TR = tr;
end
end
end
3 件のコメント
Fabio Freschi
2016 年 1 月 22 日
編集済み: Fabio Freschi
2016 年 7 月 6 日
per isakson
2016 年 2 月 12 日
編集済み: per isakson
2016 年 2 月 12 日
It's not "weird"; it's composition
Arabarra
2016 年 11 月 8 日
it's still weird that one should need to use composition instead of subclassing. TriRep (the predecessor of triangulation) used to allow subclassing (till R2016b)
カテゴリ
ヘルプ センター および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!