Pointer equivalent in MatLab

12 ビュー (過去 30 日間)
Marc Laub
Marc Laub 2020 年 7 月 14 日
コメント済み: Marc Laub 2020 年 7 月 15 日
Hey guys,
I defined an object handle class with some objects in it and those objects got a property which I called "neighbour" where object A is linked to its neighbours
classdef object < handle
properties
size
neighbour
end
methods
function g = object(size)
g.size = size;
g.neighbour = obeject.empty(0,0);
end
function link_g2g(g,neighbour)
g.neighbour(end+1)=neighbour;
neighbour.neighbour(end+1)=g;
end
end
end
I linked them together and later I also need to delete some.
I thought the way they are defined would make it possible that if I delete objects(x), that also the neighbours of object(x) would lose object(x) as their neighbour.
But that is not the case.
I have to go through all neighbours of objects(x), find out which ob the neighbours of the neighbours is objects(x), and delete that link additionally to deleting object(x) itself...
Is there a smarter way to do that? Because to run a double loop just to delet one onject and its linkges seems very inefficient. Is there a way where I delete that object and at the same time its neighbours get rid of the link to that object?
Somehow deleting an object is not sufficient because even its deleted, its still exist as the neighbour of its prior neigbours, which is not what i want.
Many thanks in advance
Best regards
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 7 月 15 日
What if you attached a listener to each, and notify() the deletion, and each node would receive the signal, check whether the given item was a neighbour, and make the appropriate change?
Potentially each object could keep track of its neighbours and notify just them.
Marc Laub
Marc Laub 2020 年 7 月 15 日
The problem with the linked list would be that there are only previous and next objects that are linked. But my objects have mutiple neighbours. I guess the listener would be the better wayin that case.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by