Why does FCLOSE not close multiple open files when passed a vector of file identifiers in MATLAB 7.1 (R14SP3)?
조회 수: 6 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2009년 6월 27일
편집: MathWorks Support Team
2014년 9월 24일
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
채택된 답변
MathWorks Support Team
2013년 10월 18일
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')
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!