필터 지우기
필터 지우기

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 CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by