Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Toggle Image Visibilty On Or Off In A GUI

Subject: Toggle Image Visibilty On Or Off In A GUI

From: Andy S

Date: 9 Dec, 2009 20:28:22

Message: 1 of 7

Hi,

I'm trying to build a small gui, which will later become part of a much bigger one. I am trying to use the output of an edit box to either display or not display an image (.jpg) that is part of an axes, when a pushbutton has been pressed.

So far, I have got it working so that:

If a number greater than 10 is entered, when the pushbutton is pressed the axes becomes invisible. If the number is less than 10, the axes and image remains visible.

I can get it to control the visibilty of an axes, however, once I apply an image to it, it no longer works. I have searched a lot to try and fix, however to no avail. So, what is the code to turn off the visibilty of an image that's on an axes???

Thanks a lot,

Andy

Subject: Toggle Image Visibilty On Or Off In A GUI

From: ImageAnalyst

Date: 9 Dec, 2009 20:53:43

Message: 2 of 7

Andy:
Been there, done that. Long explanation - ask if you really want to
know. Basically the simple work around is to put the axes inside a
panel control. Then you can just set the visibility of the panel on
or off and that will do what you expect.

Subject: Toggle Image Visibilty On Or Off In A GUI

From: Andy S

Date: 9 Dec, 2009 21:31:27

Message: 3 of 7

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c1b9a7db-5640-4668-aa34-48b4cac5a5aa@j9g2000prh.googlegroups.com>...
> Andy:
> Been there, done that. Long explanation - ask if you really want to
> know. Basically the simple work around is to put the axes inside a
> panel control. Then you can just set the visibility of the panel on
> or off and that will do what you expect.

That works great thanks! However, now the X & Y axis are displayed around the image, which I don't want. I've tried axis off, but that didn't work, what should I do?

Thanks

Subject: Toggle Image Visibilty On Or Off In A GUI

From: Andy S

Date: 9 Dec, 2009 21:38:19

Message: 4 of 7

Also, sometimes after making different adjustments to the GUI my images disappear (not intenionally) and only the blank axes is displayed. I can get around this by deleting the axes, creating a new one, and adding the image to it again. But, is there a way to avoid this?

Subject: Toggle Image Visibilty On Or Off In A GUI

From: Matt Fig

Date: 9 Dec, 2009 22:05:04

Message: 5 of 7

Instead of using a panel, one could use the handle to the image object.




function [] = mygui()
% How to make an image visible or invisible by pushbutton?

S.fh = figure('units','pixels',...
              'position',[200 200 200 200],...
              'menubar','none',...
              'numbertitle','off',...
              'name','GUI_15',...
              'resize','off');
S.ax = axes('units','pixels',...
            'position',[30 50 160 140],...
            'fontsize',8,...
            'buttondownfcn',{@ax_bdfcn,S});
S.im = load('clown');
S.R = image(S.im.X);
colormap(S.im.map);
set(S.ax,'xtick',[],'ytick',[])
S.pb = uicontrol('style','push',...
                 'units','pixels',...
                 'position',[10 10 180 30],...
                 'fontsize',14,...
                 'string','INVISIBLE/VISIBLE',...
                 'callback',{@pb_call});

    function [] = pb_call(varargin)
        st = get(S.R,'visible');
        switch st
            case 'on'
                st = 'off';
            case 'off'
                st = 'on';
        end
        set([S.R,S.ax],'visible',st)
    end
end

Subject: Toggle Image Visibilty On Or Off In A GUI

From: ImageAnalyst

Date: 9 Dec, 2009 22:15:41

Message: 6 of 7

I don't know why that is. Do you see the axes only when the image is
within the panel and if it's outside the panel there are no axes?
That's bizarre.

Sometimes the GUI won't draw controls if one of their values is not
valid. For example if you have the value property of a listbox
negative, or the value of a scrollbar less than the min proprty value,
it just won't draw that control at all, but it will put a warning
message into the command window telling you why it's not drawing the
control. Also, sometimes it won't draw a control if it just entered
into a computationally intensive loop, for example it won't update a
static text label with your new text string. To get around that you
need to issue the drawnow command right after you change the control's
property. I've never seen controls just appear and vanish at random
with no apparent reason (except what I've just listed). You said
you're making adjustments - you're probably making an invalid
adjustment.

Subject: Toggle Image Visibilty On Or Off In A GUI

From: Matt Fig

Date: 10 Dec, 2009 04:16:04

Message: 7 of 7

"Andy S" <andy_s48@hotmail.com> wrote in message <hfp5cb$re2$1@fred.mathworks.com>...
> Also, sometimes after making different adjustments to the GUI my images disappear (not intenionally) and only the blank axes is displayed. I can get around this by deleting the axes, creating a new one, and adding the image to it again. But, is there a way to avoid this?


What are the adjustments? Does the image disappear after a certain adjustment? Have you tried stepping through the adjustment code with the debugger to find out what line is creating the problem?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us