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

조회 수: 10 (최근 30일)
david jones
david jones 2016년 8월 2일
편집: per isakson 2016년 8월 10일
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
david jones
david jones 2016년 8월 10일
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 2016년 8월 10일
편집: per isakson 2016년 8월 10일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by