Prev: Delaying a signal
Next: plotting colors
From: Leo on 28 Jun 2010 12:37 I consider myself quite savvy at this sort of thing but this is really doing my head in, I have probably spent a whole afternoon trying to figure out the syntax for a callback... Please help! Callback to be called (not based on GUIDE), when value in textbox changes function var_edit_callback(hObject,eventdata,handles) Creating textbox for calling callback ui_textbox_handle = uicontrol('Parent',gcf, 'Style', 'edit',... 'String','3',... 'ForegroundColor','k',... 'BackgroundColor','white',... 'Interruptible','off',... 'Tag','var_edit',... 'Callback','var_edit_callback',gcbo,[],handle_struct); I can not for the life of me get this to work. The problem I think is that last 'Callback' line I've also tried 'Callback',[mfilename,'(''var_edit_callback'',gcbo,[],handle_struct)' 'Callback','var_edit_callback(gcbo,[],handle_struct)' etc etc as well I just can't seem to get it right. The syntax for GUIDE derived callbacks appears different and I think that's where my confusion comes from. Any help appreciated.
From: Andy on 28 Jun 2010 12:44 "Leo " <leo.xenakis(a)ricardo.com> wrote in message <i0aj3h$e0k$1(a)fred.mathworks.com>... > I consider myself quite savvy at this sort of thing but this is really doing my head in, I have probably spent a whole afternoon trying to figure out the syntax for a callback... Please help! > > Callback to be called (not based on GUIDE), when value in textbox changes > > function var_edit_callback(hObject,eventdata,handles) > > Creating textbox for calling callback > > ui_textbox_handle = uicontrol('Parent',gcf, 'Style', 'edit',... > 'String','3',... > 'ForegroundColor','k',... > 'BackgroundColor','white',... > 'Interruptible','off',... > 'Tag','var_edit',... > 'Callback','var_edit_callback',gcbo,[],handle_struct); > > I can not for the life of me get this to work. The problem I think is that last 'Callback' line > > I've also tried > 'Callback',[mfilename,'(''var_edit_callback'',gcbo,[],handle_struct)' > 'Callback','var_edit_callback(gcbo,[],handle_struct)' > etc etc as well > > I just can't seem to get it right. The syntax for GUIDE derived callbacks appears different and I think that's where my confusion comes from. > > Any help appreciated. I don't have MATLAB open at the moment, but isn't it something like: (... 'Callback', {@var_edit_callback, gcbo, [], handle_struct});
From: Steven Lord on 28 Jun 2010 13:02 "Leo " <leo.xenakis(a)ricardo.com> wrote in message news:i0aj3h$e0k$1(a)fred.mathworks.com... >I consider myself quite savvy at this sort of thing but this is really >doing my head in, I have probably spent a whole afternoon trying to figure >out the syntax for a callback... Please help! > > Callback to be called (not based on GUIDE), when value in textbox changes > > function var_edit_callback(hObject,eventdata,handles) > > Creating textbox for calling callback > > ui_textbox_handle = uicontrol('Parent',gcf, 'Style', 'edit',... > 'String','3',... > 'ForegroundColor','k',... > 'BackgroundColor','white',... > 'Interruptible','off',... > 'Tag','var_edit',... > 'Callback','var_edit_callback',gcbo,[],handle_struct); First of all, UICONTROL should error because you've specified an odd number of inputs which cannot be a number of parameter name/value pairs. > I can not for the life of me get this to work. The problem I think is that > last 'Callback' line When you specify the Callback property as a string, that string is evaluated as though you typed it at the command line. If var_edit_callback is a subfunction in the file in which you're creating ui_textbox_handle, this will not be in scope when that line executed, so even if you corrected the odd number of parameters problem, it would still error. Specify the Callback as a function handle (which could be an anonymous function) instead. 'Tag','var_edit',... Callback', @(varargin) var_edit_callback(gcbo, [], handle_struct)); -- 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: Matt Fig on 28 Jun 2010 13:06 The first two args to a callback are automatic. Anything you want to pass in goes after them. 'Callback',{@callback_func_name,W,A,R} Then in your callback you will have: function [] = callback_func_name(HOBJ,EVENTDATA,W,A,R)
From: us on 28 Jun 2010 13:09
"Leo " <leo.xenakis(a)ricardo.com> wrote in message <i0aj3h$e0k$1(a)fred.mathworks.com>... > I consider myself quite savvy at this sort of thing but this is really doing my head in, I have probably spent a whole afternoon trying to figure out the syntax for a callback... Please help! > > Callback to be called (not based on GUIDE), when value in textbox changes > > function var_edit_callback(hObject,eventdata,handles) > > Creating textbox for calling callback > > ui_textbox_handle = uicontrol('Parent',gcf, 'Style', 'edit',... > 'String','3',... > 'ForegroundColor','k',... > 'BackgroundColor','white',... > 'Interruptible','off',... > 'Tag','var_edit',... > 'Callback','var_edit_callback',gcbo,[],handle_struct); > > I can not for the life of me get this to work. The problem I think is that last 'Callback' line > > I've also tried > 'Callback',[mfilename,'(''var_edit_callback'',gcbo,[],handle_struct)' > 'Callback','var_edit_callback(gcbo,[],handle_struct)' > etc etc as well > > I just can't seem to get it right. The syntax for GUIDE derived callbacks appears different and I think that's where my confusion comes from. > > Any help appreciated. a hint: - this doc covers almost every aspect of the syntax... http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/f10-998674.html us |