How to assign pointers to an object's property?

조회 수: 10 (최근 30일)
Zoltán Csáti
Zoltán Csáti 2015년 11월 4일
답변: Zoltán Csáti 2015년 11월 5일
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