Why Matlab slows down dramatically after a few iterations in my code?

10 vues (au cours des 30 derniers jours)
david jones
david jones le 2 Août 2016
Modifié(e) : per isakson le 10 Août 2016
Hello everyone and thanks for your help.
I wrote below simple function and by using a for loop, I call this function to calculate a 200-by-200 matrix and then write it in a file. When I run it, it works fine for about 100 iterations. But after that, my computer is slowed down dramatically and afterwards, in each iteration this slowness is worsen.
It seems the speed decreases exponentially. In other words, for first iteration, it takes less than 1 second but after 150 iterations, each iteration takes more than 1 minutes. I used 'memory' and found out that Matlab pre-allocated about 4GB.
I tried to use 'clear' to clear all variable in each iteration in order to free memory without success.
Any help is appreciated.
imgs = @(c,fnt) rgb2gray(insertText(ones(200, 200, 3), [1 1], char(c), ...
'Font', fnt, ...
'FontSize', 195, ...
'AnchorPoint', 'Center', ...
'TextColor', [0 0 0], ...
'BoxOpacity', 0) ...
) > 0.55;
for char1=1:100
for ii=1:100
L=imgs(char1,fnt{ii});
L=L(:)';
StoreFile(L); % a function to write data to a file
clear L;
end
end
  6 commentaires
david jones
david jones le 10 Août 2016
The StoreFile gets a matrix name 'L' (size of 128 that is an image containing a character) and then open a file, write L and close it. That's all.
per isakson
per isakson le 10 Août 2016
Modifié(e) : per isakson le 10 Août 2016
I made an experiment, but failed to reproduce the behavior you see. I saw no slow down.
Non-printing characters caused me a bit of problem so I excluded them. "then open a file, write L and close it" does that mean ONE file or one file per image? I appended to ONE text file, which I thought was the worse case.
Proposal: Upload an executable code that demonstrates the behavior.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by