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

10 visualizzazioni (ultimi 30 giorni)
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 Commenti
david jones
david jones il 10 Ago 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 il 10 Ago 2016
Modificato: per isakson il 10 Ago 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Image Processing and Computer Vision in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by