title: Matlab uigetdir function fails unless I pause execution
body: <p>I've built an image browser with this structure (pseudocode)</p>
  
  <pre><code>function myBrowser()        
       loadFirstImage();
       uiwait;
  
       function handleKeyPress(~,event)
           if ~(isempty(event.Character))
              if(strcmp(event.Key, 'uparrow'))
                 %show next image
              end
              ... %other key calls
              if(strcmp(event.Key, 'r'))
                 generateIndividualReportData()
              end
           end
        end
   end
  </code></pre>
  
  <p>With this I can browse through images in a folder, make some operations with them and at some point I need to generate a report, for which I press 'r' key to call the <em>generateIndividualReportData()</em> function.</p>
  
  <p>This worked perfectly until I added an 'uigetdir' call inside the <em>generateIndividualReportData()</em></p>
  
  <pre><code>function generateIndividualReportData() %this breaks
      % do things
      mydir= uigetdir(pwd, 'Choose directory where X stuff is');
      addpath(mydir);
  end
  </code></pre>
  
  <p>This uigetdir is actually never called and therefore the subsequent 'addpath' call generates this error:</p>
  
  <pre><code>Error using catdirs (line 24)
  All arguments must be strings.
  
  Error in addpath (line 64)
  p = catdirs(varargin{1:n});
  
  Error in generateIndividualReportData (line 75)
  addpath(mydir);
  </code></pre>
  
  <p>However, if I pause execution before the 'uitgetdir' call, it works like a charm.</p>
  
  <pre><code>function generateIndividualReportData() %this works
          % do things
          pause(1)
          mydir= uigetdir(pwd, 'Choose directory where X stuff is');
          addpath(mydir);
  end
  </code></pre>
  
  <p>I know it is an easy/not-so-dirty solution, but I'd like to know why is this happening.</p>
  
  <p>Thanks in advance.</p>