Somewhat random error when exporting figures and Matlab crash

Hello,
I have a function which will export a number of plots. The function is called up to 500 times within a loop and the error appers to occur at random loop count values. Sometimes the error comes up with the 145th itteration, sometimes 220th but almost never for <30. This makes me think it's the function not clearing memory properly.
The error is...
"Error using print (line 82)
Unable to create output using specified size and resolution. Specify a smaller value for the PaperPosition property of the figure or specify a smaller resolution value."
My code is
print(f, '-dpng', file_name_phasor, '-r0');
I have tried saving as JPEG and tried the following...
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 4 3])
print(f, '-dpng', file_name_phasor, '-r100')
But this throws up a similar error.
The fact that Matlab crashes makes me think I'm not clearing variables properly or something. I thought however that once a function is called only the specified return variables are returned.
When I suspend plotting figures I do not have an error however.
Apologies if this is a diffuse kind of question but I'm really stuck and have tried a bunch of stuff.
Rob

回答 (1 件)

Shubh Sahu
Shubh Sahu 2020 年 5 月 5 日

0 投票

As you have mentioned you are able to create figure till 145th iteration, it seems that your system java heap memory is getting exhausted. You can increase that by following this:
MATLAB -> Home -> Preference -> General -> Java Heap Memory -> slide according to your need.
Hope it will help you
Note: I would strongly recommend you not to use plot function inside for loop.

1 件のコメント

Robert Malkin
Robert Malkin 2020 年 5 月 5 日
That is amazing Shubh. Thank you very much for the help. It has been really hard to find much on this topic. I guess the problem is my innefective implementation of plotting and loops. Much to learn!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

質問済み:

2020 年 5 月 1 日

コメント済み:

2020 年 5 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by