Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

fclose

Close one or all open files

Syntax

fclose(fileID)
fclose('all')
status = fclose(___)

Description

example

fclose(fileID) closes an open file.

fclose('all') closes all open files.

status = fclose(___) returns a status of 0 when the close operation is successful. Otherwise, it returns -1. You can use this syntax with any of the input arguments of the previous syntaxes.

Examples

collapse all

Open the badpoem.txt file, read the first line, and then close the file.

Use fopen to open the file. This function assigns a unique file id to use for reading and writing to the file.

fid = fopen('badpoem.txt')
fid = 4

Read the first line from the file using fgetl.

fgetl(fid)
ans = 
'Oranges and lemons,'

Close the file.

fclose(fid);

Input Arguments

collapse all

File identifier of an open file, specified as an integer. Before closing a file with fclose, you must use fopen to open the file and obtain its fileID.

Data Types: double

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a

Was this topic helpful?