Help with subfunction in GUI

1 回表示 (過去 30 日間)
Daniel
Daniel 2011 年 1 月 21 日
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

採用された回答

Daniel
Daniel 2011 年 1 月 25 日
Yes, I am using a GUIDE GUI. My program has upto eight conditions to process. To save lines of code I wanted to run a function inside the callback to process the conditions. I'm trying to call the function using:
[output]=function_name(input1,input2,...,inputn)
If I remove the function and instead enter the lines of code from the function into the callback it works fine. I looked at function handles but did not have any luck. Hope this makes more sense... any ideas what I can do?
  2 件のコメント
Matt Fig
Matt Fig 2011 年 1 月 25 日
And is your function FUNCTION_NAME in the M-File, at the end or what? It cannot be "inside" the callback. Just put it at the end as another subfunction of the main GUI function, as the callbacks are. Then you can _call_ it as a function from inside the callback.
Daniel
Daniel 2011 年 1 月 26 日
Thank you...

サインインしてコメントする。

その他の回答 (2 件)

Matt Fig
Matt Fig 2011 年 1 月 21 日
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
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.

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by