1

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.

Community
  • 1
  • 1
Chi Chow
  • 21
  • 1
  • 2

3 Answers3

5

Try calling fclose('all') after saveas (assuming you have no other open file handles), to make sure that saveas is closing the file handles properly.

Tom
  • 1,329
  • 6
  • 15
1

Sounds like you are not closing each file after you have saved to it. In Java you would call close() when you are finished.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
1

One bug that will supposedly fixed in the upcoming release 2011b is as follows:

Description: On some Linux systems, based on the Linux OS descriptors limit, normal use of MATLAB may trigger the following errors:

Too many files open.
Unexpected error status flag encountered. Resetting to proper

state. While some GUIs may continue to work, the MATLAB command line will consistently error. Workaround: Check the Linux OS limits using the limit command in the Linux shell:

[hostname:/home/lusername]1 % limit descriptors If the descriptors limit is set to less than 1024, reset the descriptors limit to 1024. This will be shell dependent. In tcsh, using this command in a startup file (like .cshrc) would be appropriate: limit descriptors 1024

Jonas
  • 74,690
  • 10
  • 137
  • 177