Class: matlab.io.datastore.DsFileReader
Package: matlab.io.datastore
Read bytes from file
A = read(fr,size)
A = read(fr,size,Name,Value)
[A,count] = read(___)
returns data, from the file represented by the file-reader object A
= read(fr
,size
)fr
.
The number of bytes specified in size
determines the amount of data
that is read.
specifies
additional parameters using one or more name-value pair arguments. For example, you can
specify the output type from the read operation to be A
= read(fr
,size
,Name,Value
)char
by
specifying 'OutputType','char'
.
[
returns a count of the number of bytes of data that were actually read by the
A
,count
] = read(___)read
method.
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);
Check if the file has data to read using the hasdata
method.
The read method reads 1000
bytes from the file and interprets
them as characters.
if hasdata(fr) [d,count] = read(fr,1000,'OutputType','char'); end
Read enough bytes from the file to fill 1000
characters by
setting the SizeMethod
parameter to
OutputSize
.
if hasdata(fr) [d,count] = read(fr,1000,'SizeMethod','OutputSize',... 'OutputType','char'); end