MATLAB: How to use a push button to restart a script file

pushbuttonuicontrol

I am writing a script for a tic tac toe game and I want to use a push button as an exit which will restart the game. This is how I formatted the button:
c = uicontrol('Style','pushbutton','String','Exit')
I want the script file to run from the beginning when the button is pressed. Thanks!

Best Answer

You need to add a callback:
c = uicontrol('Style','pushbutton', ...
'String','Exit', ...
'Position', [5, 5, 60, 25], ...
'Callback', @ExitCallback);
Then this callback function is called, when the button is pressed. It might look like this:
function ExitCallback(ButtonH, EventData)
... here the code for restarting
You find several correcponding examples here: FEX: 41 GUI examples.
Please try it and ask a specific question if problems occur.