Matlab uigetdir function fails unless I pause execution

129 Views Asked by At

I've built an image browser with this structure (pseudocode)

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

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 generateIndividualReportData() function.

This worked perfectly until I added an 'uigetdir' call inside the generateIndividualReportData()

function generateIndividualReportData() %this breaks
    % do things
    mydir= uigetdir(pwd, 'Choose directory where X stuff is');
    addpath(mydir);
end

This uigetdir is actually never called and therefore the subsequent 'addpath' call generates this error:

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

However, if I pause execution before the 'uitgetdir' call, it works like a charm.

function generateIndividualReportData() %this works
        % do things
        pause(1)
        mydir= uigetdir(pwd, 'Choose directory where X stuff is');
        addpath(mydir);
end

I know it is an easy/not-so-dirty solution, but I'd like to know why is this happening.

Thanks in advance.

0

There are 0 best solutions below