フィルターのクリア

Too many files open error when using load and save. fclose('all') doesn't solve the problem

2 ビュー (過去 30 日間)
Saumya Tiwari
Saumya Tiwari 2019 年 1 月 30 日
コメント済み: Saumya Tiwari 2019 年 2 月 15 日
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
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.
Saumya Tiwari
Saumya Tiwari 2019 年 2 月 15 日
Sorry, I was going to respond to this comment and then I got distracted. I tried to check what is being opened, it was a lot of java .jar files. Not sure if that has any connection to the problem at hand. I didn't see my file names as being left open, which was what I was suspecting before.
The windows support tech asked me to disable all non- windows services to see if it helps with the problem. This error takes a few days to pop up, so it will be a while before I find out if this solved the issue.

サインインしてコメントする。

回答 (1 件)

Andreas Kvalbein Fjetland
Andreas Kvalbein Fjetland 2019 年 1 月 30 日
Try usinng the clear command instead of fclose. This worked in my test here.
clear('structMatrix')
  2 件のコメント
Saumya Tiwari
Saumya Tiwari 2019 年 2 月 1 日
編集済み: Saumya Tiwari 2019 年 2 月 15 日
Thank you, seems like this solved the problem. I will update if I run into this again.
Edit: Did not work. I am clearing variables after load and save calls, no good.
Walter Roberson
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 ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by