Too many files open error when using load and save. fclose('all') doesn't solve the problem
조회 수: 1 (최근 30일)
이전 댓글 표시
My code looks like this
sourcedir = 'C:\exampleDirectory\';
for i = 1:N
exampleFilename = [sourcedir, num2str(i),'.mat'];
structMatrix = load(exampleFilename);
exampleMatrix = structMatrix.savedMatrix;
% do something on exampleMatrix
fclose('all');
end
I have tried sticking an fclose('all') on both ends yet it inevitably runs into:
Error using load
Unable to read file 'exampleFilename'.
Too many files open.
same happens with a similar save function. I tried running it in for loop instead of parfor, the problem persists. I can restart matlab and the problem goes away for a while, only to return when the open file number hits the limit. It is likely happening from load and save functions, but I can't see the code of load and save functions, neither do they output fid for me to close specifically.
Thank you,
댓글 수: 2
Walter Roberson
2019년 1월 30일
I suggest you try https://docs.microsoft.com/en-ca/sysinternals/downloads/process-explorer to monitor which files are being opened. You would then be able to tell whether it is the load() calls.
답변 (1개)
Andreas Kvalbein Fjetland
2019년 1월 30일
Try usinng the clear command instead of fclose. This worked in my test here.
clear('structMatrix')
댓글 수: 2
Walter Roberson
2019년 2월 15일
process-explorer that I mentioned would permit you to find out more about what is being opened.
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!