Search code examples
matlabmatlab-figureexit

code to close a matlab app


I have written a Matlab app with the app designer tool, and have successfully coded everything except the pesky (and most likely simple) exit button. The button itself should do what it says, close the app when clicked, but looking online has just led me to dead ends. Here is what I have written down for the exit function; it doesn't work, but its better than writing no code:

 % Button pushed function: ExitButton
    function ExitButtonPushed(app, event)
        Figurename = app.UIFigure ;
        close Figurename
    end

Solution

  • MATLAB interprets close Figurename as close('Figurename'), which is not a valid object to close. See command syntax vs. function syntax

    Use close(Figurename), or really just close(app.UIFigure).