1

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.

Carlos Borau
  • 1,433
  • 1
  • 24
  • 34
  • I've seen things like this before. It is probably related to message queues. You can try also with `drawnow`. You can also submit a bug report. – Cris Luengo Jun 19 '18 at 15:30
  • `drawnow` works too, I guess I'll leave it since it feels smoother for the user. Thanks! – Carlos Borau Jun 19 '18 at 15:47

0 Answers0