From: CyberFrog on 9 Mar 2010 12:40 hI, New to GUI development, managed to obtain this really simple GUI example but I sd not understand the following line: S = varargin{3}; % Get the structure. Why is it varargin{3}????? and not varargin{1} or 2 or 4 etc Thanks CF and the main code is: function [] = GUI_3() % Demonstrate how to hide a uicontrol from the user. % Creates a textbox and a checkbox. The state of the checkbox determines % whether or not the textbox is visible. % % % Author: Matt Fig % Date: 7/15/2009 S.fh = figure('units','pixels',... 'position',[300 300 200 130],... 'menubar','none',... 'name','GUI_3',... 'numbertitle','off',... 'resize','off'); S.tx = uicontrol('style','text',... 'unit','pix',... 'position',[10 70 180 40],... 'string','Hello',... 'backgroundcolor','r',... 'fontsize',23); S.ch = uicontrol('style','check',... 'unit','pix',... 'position',[10 20 180 35],... 'string',' Check2hide',... 'fontsize',14); set(S.ch,'callback',{@ch_call,S}) % Set callback. function [] = ch_call(varargin) % Callback for pushbutton. S = varargin{3}; % Get the structure. switch get(S.tx,'visible') case 'on' % The text is visible, make it invisible. set(S.ch,'string',' Uncheck2show'); set(S.tx,'visible','off') case 'off' % The text is invisible, make it visible. set(S.ch,'string',' Check2hide'); set(S.tx,'visible','on') otherwise % This should never happen! disp('Matlab entered the twilight zone, aborting.') close(S.fh) quit end
From: Matt Fig on 9 Mar 2010 13:28 Whenever an object calls its callback it passes at least two arguments always. The first one is it's own handle, the second is an eventdata structure. If, when you assigned the callback, you told assigned an additional argument, it will show up as the third argument.
From: CyberFrog on 10 Mar 2010 09:45 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <hn63vk$gfl$1(a)fred.mathworks.com>... > Whenever an object calls its callback it passes at least two arguments always. The first one is it's own handle, the second is an eventdata structure. If, when you assigned the callback, you told assigned an additional argument, it will show up as the third argument. Thanks alot Matt. Great GUI examples by the way, you probably noticed this was your code. Another I problem with passing data between functions actually refers to you GUI from the GUI_FEX set of examples. Basically I am developing a GUI programmatically and I have structured it using a set of nested functions i.e. function main function 1 %then call to each function to call next function function 2(set of args) end function 2 function 3 (set of args) end function 3 close(gcf) end %Update function here end I would like to now introduce this GUI2 example which keeps adding strings to a listbox so I have adopted your line of code: function [] = update(varargin) % Callback for pushbutton, adds new string from edit box. S = varargin{3}; % Get the structure. oldstr = get(S.ls,'string'); % The string as it is now. addstr = {string1, string2, string3} % The string to add to the stack. % The order of the args to cat puts the new string either on top or bottom. set(S.ls,'str',{oldstr{:},addstr{:}}); How can I keep adding to this listbox within each function as I obtain more and more data from the GUI? I have tried to call from each function: update(string1) then in another function update (string) hoping this will then add it to my update function and hence listbox. However I keep getting the error: ??? Cell contents reference from a non-cell array object. Error in ==> main>update at 54 set(listbox,'string',{oldstr{:},addstr{:}});
|
Pages: 1 Prev: If/then subsystems - I'm missing a subtle point Next: R^2 greater than 1 in regress output? |