Help with subfunction in GUI
Show older comments
I'm writting a GUI to process data sets and export values to excel spread sheets. I wrote the full code in the GUI and it worked. However, I want to move some of the code into a subfunction of the callback. When I do this everything falls apart. I get the following error:
??? Error using ==> feval
Undefined function or method 'export_button_Callback' for input arguments of type 'struct'.
Error in ==> gui_mainfcn at 95
feval(varargin{:});
Error in ==> GUI_Trial_Design at 42
gui_mainfcn(gui_State, varargin{:});
??? Error using ==> GUI_Trial_Design('export_button_Callback',gcbo,[],guidata(gcbo))
Error using ==> feval
Undefined function or method 'export_button_Callback' for input arguments of type 'struct'.
??? Error while evaluating uicontrol Callback
Is the error likely to be in calling the subfunction? Is it a syntax error? A problem with exporting to Excel? I'm not sure what error I should be looking for. Any help is greatly appreciated. Thanks ~Dan
Accepted Answer
More Answers (2)
Matt Fig
on 21 Jan 2011
0 votes
I am not sure what you mean by a "subfunction of the callback" here. It looks like you are using a GUIDE GUI, which means that all functions within the M-File are subfunctions to the main function. There are no subfunctions of subfunctions.
Assuming you mean that the function is just another subfunction in the M-File, how are you calling it? When it was working before, was the function in another M-File or what? How were you calling it then?
Walter Roberson
on 21 Jan 2011
Change the line
GUI_Trial_Design('export_button_Callback',gcbo,[],guidata(gcbo))
to
GUI_Trial_Design(@export_button_Callback,gcbo,[],guidata(gcbo))
When you name a callback via a string, the callback is called at the base workspace level; if the named function is that of a nested function, it is not visible at the base workspace level. When you use a function handle instead of a string, the handle is evaluated according to the scoping rules within the place the @ reference occurs.
Categories
Find more on Variables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!