Error writing to file: "Too many files are being opened"

I want to write an array cloud

that nothing beats an array that stores the coordinates of a circular cloud with two columns, latitude and longitude. I want these coordinates to be written to a text file this way.

 418.9517   43.9866
 419.2260   44.1501
 419.4826   44.3402
 419.7190   44.5550
 419.9327   44.7923
 420.1217   45.0497

      

With this code, I want to create several such files, storing the coordinates of one cloud in one file.

Here a

is an array with the first two columns of latitude and longitude (center of the circle) and the third radius of the circle. And z =size(a)

. (2905x3). Thus, a total of 2905 files will be recorded.

for s =1:z(1)
    r= a(s,3);

    ang=0:0.1:2*pi; 
    xp=a(s,1) + r*cos(ang);  
    yp=a(s,2) + r*sin(ang);  
    xp=xp';
    yp= yp';
    cloud = [xp,yp]

    filename = ['Shower_Cloud',s,'number.txt']
    file_id = fopen (filename,'w');
    fprintf(file_id,'%g\t',cloud[]);
    fclose(file_id);
end

      

The error when I run the code is the main problem, I cannot diagnose this problem on my own, although I have a feeling it is minor.

     >> xyz
     D:\Users\Vikram\Documents\MATLAB\Manuela\Version_2\Weather\Shower\xyz.m:
     Too many files open; check that FILES = 20 in
     your CONFIG.SYS file.

     Unexpected error status flag encountered.  Resetting to proper state.

      

Please ask if I missed something important.

+3


source to share


3 answers


This is just speculation, but strange behavior can be expected when concatenating numbers with strings. You can use num2str(s)

when creating a filename.



+4


source


Perhaps other parts of your program will lose control over open files. Use fopen('all')

to display file files open files. Perhaps this is a starting point for finding bugs.



0


source


Most likely some error at some point in your code caused many files to open without closing. Note that even if the code you posted does indeed close each file correctly, as long as you are still using the same MATLAB session, you can still open the files.

You can close all currently open files as follows:

fclose all

      

Therefore, I suggest that you first enter this at the MATLAB prompt. If you still have the error, take a look:

fopen all

      

which lists all currently open files; hopefully this gives you enough information to find the problem.

0


source







All Articles