필터 지우기
필터 지우기

Does matlab automatically close a file after loading it

조회 수: 29 (최근 30일)
Matlab_Student
Matlab_Student 2018년 1월 25일
답변: Walter Roberson 2018년 1월 25일
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.

채택된 답변

Walter Roberson
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개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by