fread

Read open target computer file

Syntax

data = fread(filesys_object, file_id)
data = fread(filesys_object, file_id, offset, numbytes)

Description

example

data = fread(filesys_object, file_id) reads binary data from the file on the target computer and writes it into matrix data. The file_id argument is the file identifier associated with an open file.

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.

example

data = fread(filesys_object, file_id, offset, numbytes) reads numbytes bytes from file_id starting from position offset and writes the block into matrix data.

Examples

collapse all

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

Open file data.dat at offset 1, read 3 bytes 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, 1, 3);
char(value)
ans =

  1×4 char array

est

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

To get a count of the total number of bytes read into data, call the length function. If numbytes bytes are not available, length(data) can be less than numbytes. length(data) is zero if fread is positioned at the end of the file.

Introduced in R2014a