Help with subfunction in GUI

2 Ansichten (letzte 30 Tage)
Daniel
Daniel am 21 Jan. 2011
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

Akzeptierte Antwort

Daniel
Daniel am 25 Jan. 2011
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 Kommentare
Matt Fig
Matt Fig am 25 Jan. 2011
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 am 26 Jan. 2011
Thank you...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Matt Fig
Matt Fig am 21 Jan. 2011
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 am 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.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by