Info

This question is closed. Reopen it to edit or answer.

save referenced "places" of an object

1 view (last 30 days)
Konstantin
Konstantin on 15 May 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi, i have objects of a class "Point" and objects of a class "Vector". Both subclasses of handle. Points will be referenced/stored as objects in vector-objects.
For example:
>> vector_a.x=Point_1_X
>> vector_a.y=Point_1_Y
>> vector_a.z=Point_1_Z
and so on with way more points and vectors.
My question is: Points can be referenced in different vectors. And i'd like to store the name of the vector objects, where points get referenced.
In the example:
After saying
>> vector_a.x=Point_1_X
the string "vector_a" should get stored automatically in the property of Point
>> Point_1_X.contained
ans = 'vector_a'
So, later, all points have to know (in their property "contained") in which vectors they are referenced.
How can I do that? Is there an built-in or a smart way to do that?
_
Thanks for your help. Hope i explained the question properly.

Answers (1)

Matt J
Matt J on 15 May 2015
You can overload the class' subsasgn method and use the INPUTNAME command there to get the string 'vector_a'. However, you will have to decide what to do when the assignment is to an object that does not have a name, as for example, when you do
vector_a{1}.x=whatever
  1 Comment
Konstantin
Konstantin on 16 May 2015
Thanks Matt. I didn't knew neither subsasgn nor Inputname, so I will try them out.
Your mentioned example, won't happen in my case, because the size of the objects is allways 1x1 so the vectors have allways a unique name. vector_a, vector_b, vector_asdf...
Thanks again

Community Treasure Hunt

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

Start Hunting!