Why does FCLOSE not close multiple open files when passed a vector of file identifiers in MATLAB 7.1 (R14SP3)?

6 vues (au cours des 30 derniers jours)
When I pass a vector of file identifiers to the FCLOSE function in MATLAB 7.1 (R14SP3), it only closes the first file and leaves the rest open. It should either close all files or warn the user that some files were left open.
The following steps should reproduce the problem:
f1 = fopen('a.txt', 'w');
f2 = fopen('b.txt', 'w');
f3 = fopen('c.txt', 'w');
f = [f1 f2 f3];
fclose(f)
fstillopen=fopen('all')
The variable "fstillopen" contains the following result:
fstillopen =
4 5

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 18 Oct 2013
The ability to close multiple files with FCLOSE by providing a vector of file identifiers is not available in MATLAB 7.1 (R14SP3).
Note that MATLAB 7.2 (R2006a) produces an error when a vector of file identifiers is passed to FCLOSE.
As a workaround, you can close multiple files as defined with a vector of file identifiers by using a FOR loop and the FCLOSE command. For example:
f1 = fopen('a.txt', 'w');
f2 = fopen('b.txt', 'w');
f3 = fopen('c.txt', 'w');
f = [f1 f2 f3];
for i=1:length(f)
fclose(f(i));
end
fstillopen=fopen('all')
Or, if you would like to close all open files, you can enter the following:
fclose('all')

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Produits


Version

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by