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

6 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 18 Okt. 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')

Weitere Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Produkte


Version

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by