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

Upvotes: 0

Views: 11510

Answers (3)

albusSimba
albusSimba

Reputation: 469

You can do this

%Draw EXIT push button refer to exitFcn function
uicontrol(handles(1),'Style','PushButton','Units','normalized',...
    'Position',[0.8158 0.05 0.1 0.1],...
    'String','Exit',...
    'Callback',@ButtonexitFcn);

return;
%---------------------------------------------------------------------
function ButtonexitFcn(varargin)
%This function close all figures and terminate program
    close all;
return;

Upvotes: 0

sco1
sco1

Reputation: 12214

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).

Upvotes: 4

writing

close all force ;

seemed to do the trick; as it closes all processes in the Matlab code that were running, which works perfectly for what I want.

Upvotes: 3

Related Questions