I have a for
loop that saves an image at each iteration using saveas(gcf,[%link,'.jpg'])
It works well at the beginning, but crashes and displays an error message like this:
??? Error using ==> print at 339 Cannot create output file '/20110301/20110301225100.jpg'
Error in ==> saveas at 155
Error in ==> TSI_forecast_display_cloud_decision at 153 java.io.FileNotFoundException: /home/cwchow/.matlab/R2010a/matlab.prf (Too many open files) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.(Unknown Source) at java.io.FileOutputStream.(Unknown Source) at com.mathworks.services.Prefs.save(Prefs.java:295) at com.mathworks.services.Prefs$SavePrefsThread.run(Prefs.java:702)
I get a similar result if I use print
. I guess MATLAB is not closing files properly resulting in too many open files. Can anyone tell me how to avoid this error?
UPDATE:
I tried both figure handle and fclose('all')
. I even used close all
, they do not work. I still get the same error. I checked the system limit, it's already 1024.