How to assign pointers to an object's property?

10 次查看(过去 30 天)
I want to create a finite element object oriented program. I have a class Node. Since the nodes in a finite element mesh (represented by class Mesh) are distinct, I created the Node class to be a value class. When I instantiate the array of objects from class Node, I assign that object array to the nodes property of Mesh. I have an Element class too, representing a finite element. I also create an object array from this class and assign it to the element property of Mesh. It is clear up to now.
Since the finite element nodes also belong to the elements, I want to assign some of the nodes to the appropriate elements. But copying the nodes results in data redundancy, therefore I want to assign pointers to the Node objects so that the localNodes property of Element contains an array of pointers to the specific nodes. How should I modify my classes below to achieve it?
The Node class:
classdef Node
properties
coordinate;
end
methods
% Not interesting for this example
end
end
The Element class:
classdef Element
properties
localNodes; % the object instantiated from the class Element
% will store an array of pointers to the
% appropriate elements of the object array stored
% in Mesh.nodes. How can I assign these pointers
% to Element.localNodes?
end
methods
% Not interesting for this example
end
end
The Mesh class:
classdef Mesh
properties
nodes; % its object will contain an object array of Node
elements; % its object will contain an object array of Element
end
methods
% Not interesting for this example
end
end

采纳的回答

Zoltán Csáti
Zoltán Csáti 2015-11-5
After thorough discussions, the answer can be found on stackoverflow.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Construct and Work with Object Arrays 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by