Does matlab automatically close a file after loading it
16 ビュー (過去 30 日間)
古いコメントを表示
I have a big for loop that loads each file in a directory and performs some calculations. I wonder if matlab still keeps these file loaded after it finishes the for loop.
0 件のコメント
採用された回答
Walter Roberson
2018 年 1 月 25 日
load() and imread() and audioread() and csvread() and dlmread() automatically close files they open.
On Mac and Linux, and on MS Windows that does not have Excel installed, xlsread() and readtable() automatically close files they open.
On MS Windows with Excel installed, xlsread() and readtable() use ActiveX to talk to Excel to do the loading. In the last few releases (starting R2016a or so), when it does that, it "caches" the previous connection, so that if you read from the same file several times, it does not have to rebuild the connection. My memory is that only the immediately previous file is retained, so if you were to read P, P, Q, P then the second P would reuse the connection, the Q after that would close the connection and build a new one for Q, and the P after that would close that connection and open a new on for P again.
Historically, there have been cases where some operations did not always close files when they should have.
At any point, you can determine how many files are open by looking at the output of fopen('all')
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!