Does matlab automatically close a file after loading it
24 次查看(过去 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!