From: Steven Lord on 29 Jun 2010 09:15 "Audric " <audricdebaisieux(a)gmail.com> wrote in message news:i0cq42$lu7$1(a)fred.mathworks.com... > Hi, > > I am Audric and I use Matlab 2010a. > I face a problem when implementing my Matlab GUI. In some callbacks I > delete buttons and replace them by others. The problem is that my > structure h is updated in the function but not outside (h.fig is the > figure, h.button1 the first button...). I do not use nested functions. > > Here is a structure of a callback where the problem stands > > function detailsportfolioscallback(hObject, eventdata, h) > % Delete of previous buttons in panel parameters > delete(h.button1); > h = rmfield(h, 'button1'); > % Creation of new buttons > h.button2 = uicontrol(h.panel1,'Style','checkbox', 'String','olcf', > 'Position',[30 480 150 20]); > % Assignement of callback functions > set(h.button2, 'callback', {@button2callback, h}); Note that this makes a copy of the handles structure _as it exists right now_ and that copy will be passed into button2callback -- if the handles structure changes after this line of code the copy passed into button2callback will NOT change to reflect those changes. If you need to 'delete' buttons and 'recreate' them later on, rather than deleting buttons and creating new ones, I would probably change the Visible property to turn invisible those buttons you want to 'delete' (in case you need to 'recreate' them later on) and turn visible those buttons you 'create' or 'recreate'. Also note that while you have changed the handles structure _inside this callback function_ you don't update the "master" copy associated with the figure, so all the changes to h disappear along with that copy of the handles structure when the callback function's execution completes. You would need to use GUIDATA to update the master copy AND (if any callbacks are already running) force the handles structures in those other callback functions to synchronize with the new master copy, again with GUIDATA. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: Audric on 29 Jun 2010 10:57 Perfect. I defined all GUI components in the "main" gui function. Then I just play with the property "Visible" (on, off) in the different callbacks. Works perfectly. Thanks a lot
|
Pages: 1 Prev: Generalized data distribution Next: How to close m-file with code |