Does matlab automatically close a file after loading it
25 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Matlab_Student
el 25 de En. de 2018
Respondida: Walter Roberson
el 25 de En. de 2018
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 comentarios
Respuesta aceptada
Walter Roberson
el 25 de En. de 2018
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!