Get the "handle number" of a standard handle class

How can I ...
-Get the "handle number" (like the handle number returned when using hdgetset classes(ex : 203.0024)) of a myclass object which is of a "standard" handle class (myclass<handle)
-Store this "handle number" in a text variant
-And then retrieve my original object by this "handle number"
Thanks for you help!!! Gabriel

 채택된 답변

Walter Roberson
Walter Roberson 2012년 2월 29일

1 개 추천

You can attach arbitrary (binary) data to a graphics object by setting its UserData property, or by using setappdata() on it.

추가 답변 (3개)

Andrew Newell
Andrew Newell 2012년 2월 29일

1 개 추천

Setappdata seems best because of the limitations on using the UserData property (see How can I keep track of my GUI object handles?. You can store handles, as in the following example:
x = 1:10;
h = plot(x,x);
ha = @(x) x^2;
setappdata(h,'myHandle',ha)
f = getappdata(h,'myHandle');
f(2)
ans =
4
Daniel Shub
Daniel Shub 2012년 2월 29일

0 개 추천

You cannot do this directly. I don't understand why you would want to. Why not just pass the object around? MATLAB is pretty smart about memory management and doesn't make copies of handle object every time they are referenced.
If you really want to do it, you could subclass the handle class with something like myhandle. This new class could have a public property "h" which gets set at creation with a unique number. There are a number of ways that I can think of to keep track of the handle number to guarantee that they are unique. Then just make myclass<myhandle.

댓글 수: 6

I _think_ what Gabriel is asking for is an object serialization method. Which MATLAB does have internally but has never exposed.
@Walter, it is possible that I am wrong. I interpreted hdgetset to be hgsetget and the 203.0024 to be a handle to a graphics object.
Hard to say. We'll have to wait for an update from Gabriel.
I am building a mass transit simulation interface. The user use tools to build the mass transit system over an image. What I need is to make a link between the graphic objects (lines, etc.) and the "simulation objects" they represent(tracks, stations, etc.). The only way that I have found to store information into a graphic object is by changing their Tag property. The problem is that the Tag property only accept text. I don't want to store the graphic objects into my "simulation objects". If you have an alternate method to arrive to that goal, it could also solve my problem. Thanks.
So my question was basically if an object of class Myclass<handle have a handle that can be retrieved and used to retrieve back this object like the graphics objects have.
Gabriel, object handles that are not handle graphics objects, do *not* have a representation of the kind you are seeking.

댓글을 달려면 로그인하십시오.

Gabriel Caron L'Écuyer
Gabriel Caron L'Écuyer 2012년 2월 29일

0 개 추천

Thanks, it solved my problem. Gabriel

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by