Prev: Eye Tracking
Next: Generalized data distribution
From: Audric on 29 Jun 2010 08:49 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}); end Strange that i use exactly the same as here: http://blogs.mathworks.com/pick/2007/12/28/matlab-basics-guis-without-guide/ Maybe I should use something like guidata but for the update of the figure and its components... Could you help me please? Regards,
From: Frédéric Bergeron on 29 Jun 2010 09:24 > > Maybe I should use something like guidata but for the update of the figure and its components... > > Could you help me please? > > Regards, Hey, I'm programming a GUI with about 15 callback function at the moment. I use guidata and it works very well. Here's how I do it. The first and last lines of all my callback functions: %Variables from another functions global XFIT YFIT ZFIT handles=guidata(gcbf); cut_fill_ratio=getappdata(handles.champ,'cut_fill_ratio'); %[program from the callback function] %Saving variables for other functions set(handles.plan_dessin,'edgecolor',[48 48 48]./255,'facealpha',0.2,'hittest','off'); guidata(gcbf,handles); So basically I use a mixed method with guidata, setappdata/getdata and global variables. Guidata for handles, setappdata/getappdata for variables used in like 2 to 5 subfunctions, and global variables for varaiables wich are used in almost all of my callback functions. I do not claim my method to be the best, I even think (from what I've read) that using global variable may causes more problems than what you get from being easy to write. Guidata is a good one thought. Bye
|
Pages: 1 Prev: Eye Tracking Next: Generalized data distribution |