|
From: | Michael Goffioul |
Subject: | Re: Function handle with arguments for GUI callback |
Date: | Mon, 11 Mar 2013 14:31:04 -0400 |
On 11 March 2013 17:34, Michael Goffioul <address@hidden> wrote:
Using a cell array is the right approach. It is supported. What error do you get and what code are you using? Also please note that a GUI callback always get the object handle and an event data as first 2 arguments. Whatever arguments you specify in the cell array starts at position 3 in the callback argument list.Michael.Thanks, I have made some progress since my initial email.In my main function, I create a variable called "gui" as the output of a sub-function called create_interface:gui = create_interface;In the sub-function create_interface, I add various fields to the gui structure which are handles to the various UI components, such as:% Add pop-up menus for dimension choice of each inputstrings = {'Nominal dimensions|Measurement file'};width = [0.5 0.5 0.5];gui.dim_choices = cell(size(gui.inputs_txt));for k=1:length(gui.inputs_txt)gui.dim_choices{k} = uicontrol('Style','popupmenu','String',strings,...'Units','normalized','Position',[0.23 y_pos(k) width(k) 0.1],...'BackgroundColor','w','Parent',gui.inputs_panel,'Callback',...address@hidden,num2str(k),gui});endI have worked out that the first argument to the function handle callback needs to be converted to a string. I am also passing the gui structure as a second argument because I couldn't figure out a way of using the second default argument (eventdata - there doesn't seem to be much documentation about it).
However, if I start using the index k (which has a sensible value between 1 and 3), as in:function update_browse_btn(src,data,k,gui)% Called when user activates popup menudisp(['k = ' num2str(k)]);val = get(src,'Value')gui.browse_btns(k,1)endI get the following error:>> k = 1val = 2error: update_browse_btn: A(I,J): row index out of bounds; value 49 out of bound3error: called from:error: <path_to_my_file> at line 185, column 3I can't then close the GUI, I need to click on the console to activate it, which triggers the following error message:error: octave_base_value::convert_to_str_internal (): wrong type argument `<unknown type>'error: octave_base_value::convert_to_str_internal (): wrong type argument `<unknown type>'error: octave_base_value::convert_to_str_internal (): wrong type argument `<unknown type>'error: octave_base_value::double_value (): wrong type argument `<unknown type>'error: octave_base_value::convert_to_str_internal (): wrong type argument `<unknown type>'error: octave_base_value::convert_to_str_internal (): wrong type argument `<unknown type>'error: octave_base_value::convert_to_str_internal (): wrong type argument `<unknown type>'I then need to press Enter to regain control and close the figure with the close command.The syntax gui.browse_btns{k} results in a similar behaviour.
[Prev in Thread] | Current Thread | [Next in Thread] |