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

8 ビュー (過去 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 Center および File ExchangeImage 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