How to nest a function within the pushbutton callback function?
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen

1 Kommentar
Stephen23
am 2 Okt. 2019
"How to nest a function within the pushbutton callback function?"
The best answer is to forget about bloated GUIDE and write your own GUI code, then you can use nested functions for your callbacks (as well as gaining simpler, more efficent code, over which you have much more control).
Antworten (1)
Walter Roberson
am 2 Okt. 2019
You appear to be using GUIDE. Nesting functions is not recommended with GUIDE. In order to nest functions, every function in the same .m file must have an "end" statement that matches the "function" statement. GUIDE does not know how to edit files that have "end" matching "function", and will not be able to work with the .m file once the "end" are put in.
Your code assigns y only within function fnc . Outside of fnc then y is unreachable: it would go out of scope as soon as the call to fnc returned. You would have to call fnc with an appropriate parameter, and you would probably assign the result of the call to fnc to a variable. With fnc being a nested function inside pushbutton1_Callback, the call to fnc would have to be within pushbutton1_Callback .
Your function fnc takes a single parameter that you have named ErrDrive . It is not obvious at the moment where you are going to find data to pass as that parameter; perhaps an appropriate value is stored in the handles structure ?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!