On 2/7/2013 10:46 AM, Chaitanya Bhat wrote: > Hi all, Here's what I'm attempting... > 1) I define a figure handle 'h=plot(x,y)' in one function. > 2) I declare 'h' as global > 3) I recall this 'h' in a different function, trying to use it with > 'copyobj(h,handles.axes1)' where axes1 is a different axes than where > 'h' was originally plotted. > > I get an error with copyobj, that 'h' is an invalid handle. > > As a check, I tried using the copyobj command, similarly, but within the > first function where 'h' was originally defined. And that works just fine. > > Am I to understand that I cannot use figure handles this way, declaring > them as globals, between multiple functions? Is there a way around this?
The handle itself is only valid for the given object in the given object hierarchy--its value is of no meaning in any other context.
To use an object which is a copy via copyobj, you create a new instance handle of the copy in the new object hierarchy. There's an example of this in
You can, of course, make handles global and access them from various contexts, but they always must refer back to the original object; they're of no value other than that.
They're no different in that regard than, say, a fid handle obtained for i/o on an external file--that fid isn't of any relevance to anything except i/o on that particular file while that particular connection is/remains unbroken.