fclose

Close target computer file

Description

example

status = fclose(filesys_object,file_id) closes an open file in the target computer file system. file_id is the file identifier associated with an open file.

You can have at most 128 files open on the target computer at the same time.

fclose does not close standard input, standard output, or standard error.

Note: The SimulinkRealTime.fileSystem object will be removed in a future release. See the release note for file system commands to use instead. These commands use the SimulinkRealTime.openFTP function and the functions for the MATLAB ftp object.

Examples

collapse all

Open file data.dat, write to it, and close it again.

Open and write file.

tg = slrt;
filesys_object = SimulinkRealTime.fileSystem(tg);
file_id = fopen(filesys_object, 'data.dat', 'w');
fwrite(filesys_object, file_id, 'test')

Close file.

fclose(filesys_object, file_id)
ans =

     0

Open file data.dat, read from it, and close it again.

Open and read file.

tg = slrt;
filesys_object = SimulinkRealTime.fileSystem(tg);
file_id = fopen(filesys_object, 'data.dat', 'r');
value = fread(filesys_object, file_id);
char(value)
ans =

  1×4 char array

test

Close file.

fclose(filesys_object, file_id)
ans =

     0

Input Arguments

collapse all

File system object created by using the SimulinkRealTime.fileSystem creation function.

The file system object represents the target computer file system. You work with the target computer file system from the development computer by using file system methods.

Example: fsys

Data Types: struct

Pass this value to functions that access files on the target computer.

Example: h

Output Arguments

collapse all

If the file closed properly, the value is 0, otherwise it is -1.

Introduced in R2014a