0

I have this code which imreads several 20x20 monochromatic .bmp's. The first call, though, takes very long (up to hours). Immediately after it, everything just flows normally. I have seen mention of another MATLAB function (sortrows) also taking unusually long at the first call, but no answer to that (MatLab's slow first call of sortrows()). Suggestions?

The only thing happening before the first imread call is the loading of a 1000-dimensional vector. Is this what's hindering performance?

The code looks like that:

 load('W','W');
 c = 1;
 while c > 0.01;
   run readimage
 end

readimage:

for k = 1:1000;
  l = sprintf('%d',k);
  m = '.bmp';
  m = strcat(l,m);
  X = imread(m);
...

The first image is just a handwritten zero. It loads just fine if I try to load it elsewhere.

LW001
  • 2,452
  • 6
  • 27
  • 36
wet
  • 103
  • 3
  • can you supply your code (with the imread call) and the first bmp image? – ibezito Apr 12 '16 at 07:13
  • I strongly suspect that the problem is not with the imread call. Instead of pressing "Run" button, press "Run and time". it will output the runtime of each function. If you supply this output as well, we will have more information in order to understand what could be the problem – ibezito Apr 12 '16 at 07:32
  • no function call should take hours, the drag must be somewhere else in the code. Time each section of your code using tic toc or as @drorco suggested and find where the drag is. – GameOfThrows Apr 12 '16 at 08:05
  • Got it. I was timing it with tic toc, and the last toc was always the one right before the imread. As it turns out, for some reason (does anyone know what reason?), it would only display the toc's after the whole code was done. It didn't get stuck on the imread, but rather simply stopped displaying the toc's and other things meant to inform me about at what point it was, precisely after the first imread. I had not seen the code being finished before, only afterwards, so I hadn't thought of that. I played with `k` a bit and figured it... – wet Apr 12 '16 at 08:20

0 Answers0