MATLAB: How nest functions in GUIDE

callbackfunctionfunctionsguidenestedprogramming

The problem are not easy as it seems. I'm programming the GUI of a script where some data (numbers) are entered, then the program does its complex calculations and places the results in 'Static text'; this is activated by pressing a button called 'calculate'. Then, programming is done with functions, total'm 16, and I've done is to put all that code in the callback button 'calculate', but when I run nothing happens. Is it because the functions of the GUI end in 'return' while the scheduled end in 'end'?.
function pushbutton1_Callback(hObject, eventdata, handles,principal)
%hObject handle to pushbutton1 (see GCBO)
function 1
...return
function 2
...return
function 3
...return
etc

Best Answer

Nested functions must have an end matching their function statement, and they must be enclosed in a function that has an end matching its function statement.
Any one .m file must be consistent: its functions can either all not have the matching end statement (which GUIDE generates) or its functions can all have the matching end. It is not permitted to mix the two styles in one .m .
In order to put nested functions into a .m generated by GUIDE, you would need to manually add matching end statements for the generated code.
You could also store the containing function into a different .m . GUIDE does not require that all functions be in the one single .m file that it generates.