How nest functions in GUIDE?

1 view (last 30 days)
Peter Diaz
Peter Diaz on 25 May 2016
Commented: Peter Diaz on 10 Jun 2016
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

Accepted Answer

Walter Roberson
Walter Roberson on 25 May 2016
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.
  1 Comment
Peter Diaz
Peter Diaz on 10 Jun 2016
Thanks, It helped me to understand that the pushbutton callback converts on the main function when I copied my code, so I had to erase the name of the first function.

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!