Effacer les filtres
Effacer les filtres

Get the "handle number" of a standard handle class

7 vues (au cours des 30 derniers jours)
Gabriel Caron L'Écuyer
Gabriel Caron L'Écuyer le 29 Fév 2012
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

Réponse acceptée

Walter Roberson
Walter Roberson le 29 Fév 2012
You can attach arbitrary (binary) data to a graphics object by setting its UserData property, or by using setappdata() on it.

Plus de réponses (3)

Andrew Newell
Andrew Newell le 29 Fév 2012
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 le 29 Fév 2012
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 commentaires
Gabriel Caron L'Écuyer
Gabriel Caron L'Écuyer le 29 Fév 2012
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.
Walter Roberson
Walter Roberson le 29 Fév 2012
Gabriel, object handles that are not handle graphics objects, do *not* have a representation of the kind you are seeking.

Connectez-vous pour commenter.


Gabriel Caron L'Écuyer
Gabriel Caron L'Écuyer le 29 Fév 2012
Thanks, it solved my problem. Gabriel

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by