title: MATLAB: how to make my function wait for GUI input
body: <p>I am trying to make a GUI for a tic tac toe game I made. Here is the code I have for the GUI so far:</p>
  
  <pre><code>function fig=TTTGUI()for 
  
  close all
  %initial creation
  
  fig=figure('pos',[100 50 820 640]);
  txtbx=uicontrol('style','text','parent',fig,'pos',[640 320 160 300]);
  B0=uicontrol('style','pushbutton','parent',fig,'pos',[640 200 40 40],'string',0);
  B1=uicontrol('style','pushbutton','parent',fig,'pos',[680 200 40 40],'string',1);
  B2=uicontrol('style','pushbutton','parent',fig,'pos',[720 200 40 40],'string',2);
  B3=uicontrol('style','pushbutton','parent',fig,'pos',[760 200 40 40],'string',3);
  
  %set number of players
  players=[];
  set(txtbx,'string','how many players? (1 or 2)');
  set(B1,'callback','players=1;');
  set(B2,'callback','players=2;');
  %stop and wait here
  
  end
  </code></pre>
  
  <p>I want all of my functions to stop at this point and wait until the variable <code>players</code> changes, which only happens from button 1 or 2 being presses.</p>
  
  <p>I have looked at 'waitfor', 'uiwait', 'pause', and a couple other functions but I can't find what I am looking for. Or maybe I dont quite understand how to use those functions.
   How do I make my functions wait for one of those 2 buttons to be pressed? If another button is pressed, it should have no effect.</p>