Help with subfunction in GUI
显示 更早的评论
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
采纳的回答
更多回答(2 个)
Matt Fig
2011-1-21
0 个投票
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
2011-1-21
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Variables 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!