From: Rachel Laughs on
I have a programmatic GUI which, when run, creates an array that is then displayed using "imagesc()" (parented onto some previously made axes)
I want this image to disappear and re-appear when a toggle button is clicked by setting its 'visible' property to 'off'

Problem: how to get handle of image? Documention says that i can use "h=imagesc(..." or "h=image(.." or "h=imgca" etc. but when I use it and then try to perform the following:

" set(h,'visible','off') "

Only the AXES disappear, and the image itself remains. How do I grab the handle of the image to set its visibility to off? This has been a head-scratcher for me all week, and I would really love to figure out without having to re-create the image every time i click the button.

thank you very much!
From: Dave Berger on
"Rachel Laughs" <remove.thisrachellaughs(a)gmail.com> wrote in message <hi3f58$t8$1(a)fred.mathworks.com>...
> I have a programmatic GUI which, when run, creates an array that is then displayed using "imagesc()" (parented onto some previously made axes)
> I want this image to disappear and re-appear when a toggle button is clicked by setting its 'visible' property to 'off'
>
> Problem: how to get handle of image? Documention says that i can use "h=imagesc(..." or "h=image(.." or "h=imgca" etc. but when I use it and then try to perform the following:
>
> " set(h,'visible','off') "
>
> Only the AXES disappear, and the image itself remains. How do I grab the handle of the image to set its visibility to off? This has been a head-scratcher for me all week, and I would really love to figure out without having to re-create the image every time i click the button.
>
> thank you very much!

Rachel,

I think you'll have to post some of your code or example code that captures your problem. If you try the following example, it seems to work for me:

h=imagesc(peaks);
set(h, 'visible', 'off')
set(h, 'visible', 'on')

-Dave
From: ImageAnalyst on
I think you need to use findobj() to get all the child objects of the
axes, one of which will be the image contained within it. I know,
it's a pain, so what I usually do when I need to do that is to put the
axes inside a panel. Then you can just set the panel visibility on or
off to hide or show the axes and you don't have to worry about the
axes anymore (I mean you don't have to worry about the axes being a
child of the panel - it just works seamlessly like you'd expect).
From: Rachel Laughs on
Ah, so I see..

So the setup of my code is something like the following, where i store all handles into a self-made structure, with some toggle buttons having callbacks to hide groups of components:

===
S.f = figure('name','new fig');
S.HofAXES1= axes('units','pixels','visible','on','position',[25 75 300 300]);
S.HofAXES2= axes('units','pixels','visible','on','position',[75 25 25 25]);
S.HofAXES3= axes('units','pixels','visible','on','position',[150 25 25 25]);
S.HofAXES4= axes('units','pixels','visible','on','position',[225 25 25 25]);
S.HofAXES5= axes('units','pixels','visible','on','position',[300 25 25 25]);

axes(S.HofAXES1)
S.theimage=imagesc(peaks);

%organize GUI components by group:
S.group(1) = {[S.HofAXES1,S.theimage]};
S.group(2) = {[S.HofAXES2]};
S.group(3) = {[S.HofAXES3,S.HofAXES4,S.HofAXES5]};

%here would be callback funtion for some button to hide some groups
set([S.group{1},S.group{2}],'visible','off')
===

been playing around with a blank slate, after your comments, and with that above "sample" code, works perfectly like how i'd want.

My conclusion is that somewhere in my real code (too complicated to post here and explain. lots of intertwined callbacks, as there is quite a bit more to the GUI than just that) the imagesc or axes handles are being overwritten by something, so that when it is called upon in my set() statement, it's not actually a handle anymore.

Any ideas on what might accidentally overwrite a handle?


"Dave Berger" <dberger(a)REMOVEsysplan.com> wrote in message
> I think you'll have to post some of your code or example code that captures your problem. If you try the following example, it seems to work for me:
>
> h=imagesc(peaks);
> set(h, 'visible', 'off')
> set(h, 'visible', 'on')
>
> -Dave
From: Rachel Laughs on
So my code has a pushbutton callback in which the array is produced, and the imagesc() function used on it. then another button, with a totally separate callback function, that uses the structure as input, to make the new image disappear/reappear. for example like this:

===
%inside Pushbutton 1's callback
axes(S.existing_axes);
S.image_handle = imagesc(some_array);
set(S.button2,'callback',{@button2_call,S})

....
%inside Button 2's callback:
set([S.existing_axes, S.image_handle],'visible','off')
===

This is where I get the error message in the second callback:

??? Error using ==> set
Invalid handle

??? Error while evaluating uicontrol Callback


why is it that I can use the exact same set() statement in the first callback and effectively 'hide' the axes and image, but when I try to pass the handle via the structure to the second callback, the handle is lost?

thanks..