invalid file identifier when more text files are introduced

hi, I'm new to matlab. I wrote a code that: 1) reads many text files 2)writes new text files using data from the files it read; 3) plots the data from the newly written files.
The code works, but only with a limited number of text files (~60). When I have it read a large number of text files, this is the error:
--------------- Error using textscan Invalid file identifier. Use fopen to generate a valid file identifier.
Error in Copy_of_readall_becca (line 138)
java.io.FileNotFoundException: /Users/Becca/.matlab/R2011b/matlab.prf (Too many open files) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:179) at java.io.FileOutputStream.<init>(FileOutputStream.java:131) at com.mathworks.services.Prefs.save(Prefs.java:305) at com.mathworks.services.Prefs$SavePrefsThread.run(Prefs.java:712) The desktop configuration was not saved successfully >>
Any help would be appreciated.

답변 (5개)

Matt Kindig
Matt Kindig 2012년 3월 22일
I'm not that familiar with the Java errors that Matlab can throw, but this one looks like you have too many open file identifiers. After you are done processing each file (in the loop), you should close the file, like this:
fclose(fid)
where fid is your file identifier.
Jason Ross
Jason Ross 2012년 3월 22일

0 개 추천

First, check that you at closing any things you are opening, as Matthew suggests. If you are doing that, check the outputs of the "limit" (or "limits") command on your machine. The "descriptors" number is the number of file handles you are allowed to have open. You may need to raise this number.
You can check how many are in use using a technique similar to the following:
Becca
Becca 2012년 3월 22일
Thanks , that did help , but it still says there are too many files open. I think the problem might be because there are nested for loops? Example:
For i=1:nfiles,
fid=fopen(file_to_be_read); fid1 = fopen(file_to_be_written) ;
Nested for loops here that use fid and fid1 ;
fclose(fid); fclose(fid1);
end

댓글 수: 2

Why do you keep two fids? Can't you do it sequentially?
oh, i didn't think of that. is that better?

댓글을 달려면 로그인하십시오.

Becca
Becca 2012년 3월 22일

0 개 추천

nevermind, got it sorted !! thanks guys! (first time posting a question on this site) .. I missed a fclose on one of the fid's.
cheers, becca
Walter Roberson
Walter Roberson 2012년 3월 22일

0 개 추천

Becca's missing fclose is the most common cause of this kind of problem. It has been known, though, for MATLAB internal routines to "leak" file descriptors, to run out of slots to open files even though fopen('all') shows no files open. If you have an fopen / fclose loop that runs out after fid = 15, or after fid = 255, then you are probably encountering a combination of MATLAB bug and operating system limit.

카테고리

도움말 센터 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

질문:

2012년 3월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by