seek
Class: matlab.io.datastore.DsFileReader
Namespace: matlab.io.datastore
Seek to a position in the file
Syntax
numBytes = seek(fr,n)
numBytes = seek(fr,n,Name,Value)
Description
moves the file position indicator by numBytes = seek(fr,n)n bytes past current position in
the file specified by the fr object. seek returns
the actual number of bytes by which the position indicator was moved.
specifies additional parameters using one or more name-value pair arguments. For
example, you can specify the starting position of the numBytes = seek(fr,n,Name,Value)seek operation
by specifying 'Origin','start-of-file'.
Input Arguments
Name-Value Arguments
Examples
Seek to Position in File and Read
Create a file-reader object for a file, seek to the desired starting position, and read a portion of the file.
Create a DsFileReader object for
airlinesmall.csv.
fr = matlab.io.datastore.DsFileReader('airlinesmall.csv');The airlinesmall.csv file has variable names at the beginning
of the file. The variable names line ends at the position marked by
299 bytes. To get past the variable names line, use the
seek method to move the read pointer to the starting
position.
seek(fr,299,'RespectTextEncoding',true);Read the first 1000 characters.
if hasdata(fr) d = read(fr,1000,'SizeMethod','OutputSize','OutputType','char'); end
Version History
Introduced in R2017b