From: Gonzalo on 29 Jun 2010 22:08 Hi all, I'm building a GUI and I'm having an issue using a value from a popup menu inside a function. Any ideas why is not working? See below: function simple_gui hpopup = uicontrol('Style','popupmenu',... 'String',{'Cold','Hot'},... 'Position',[350,20,100,25],... 'Callback',{@popup_menu_Callback}); hpopup2 = uicontrol('Style','popupmenu',... 'String',{'North','South'},... 'Position',[350,50,100,25],... 'Callback',{@popup_menu_Callback2}); function popup_menu_Callback(source,eventdata) str = get(source, 'String'); val = get(source,'Value'); switch str{val}; case 'Cold' temp = 'cold'; case 'Hot' temp = 'hot'; end end function popup_menu_Callback2(source,eventdata) str = get(source, 'String'); val = get(source,'Value'); switch str{val}; case 'North' region = 'north'; case 'South' region = 'south'; end end function plotbutton_Callback(source,eventdata) disp(temp) disp(region) end
From: ImageAnalyst on 29 Jun 2010 22:58 Maybe because you don't have a "plot" push button defined, or if you do, it doesn't have access to temp and region. Once your popup callbacks return, those local-scope variables are lost/destroyed so nothing else sees them. Make them global or use setappdata/getappdata or something like that.
From: Matt Fig on 29 Jun 2010 23:05 What issue? Be specific. Are your functions nested or not (the way you have it there is a missing END)? There is a callback for a pushbutton but no pushbutton defined, why?
From: Gonzalo on 29 Jun 2010 23:52 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <i0ec9k$m1p$1(a)fred.mathworks.com>... > What issue? Be specific. > Are your functions nested or not (the way you have it there is a missing END)? > There is a callback for a pushbutton but no pushbutton defined, why? Sorry, I forgot to include hplot = uicontrol('Style','pushbutton','String','Plot!',... 'Position',[150,10,80,25],... 'Callback',{@plotbutton_Callback});
From: Gonzalo on 29 Jun 2010 23:53
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <9f43eec4-667e-415d-82aa-9513cb92f861(a)w31g2000yqb.googlegroups.com>... > Maybe because you don't have a "plot" push button defined, or if you > do, it doesn't have access to temp and region. Once your popup > callbacks return, those local-scope variables are lost/destroyed so > nothing else sees them. Make them global or use setappdata/getappdata > or something like that. How can I make the plot button have access to temp and region?? |