How to assign pointers to an object's property?

10 views (last 30 days)
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

Accepted Answer

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

More Answers (0)

Categories

Find more on Construct and Work with Object Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!