Class: matlab.io.datastore.DsFileReader
Package: matlab.io.datastore

Determine if data is available to read


tf = hasdata(fr)


tf = hasdata(fr) returns logical 1 (true) if there is data available to read from the file-reader object specified by fr. Otherwise, hasdata returns logical 0 (false).

Input Arguments

expand all

File-reader object, specified as a matlab.io.datastore.DsFileReader object. To create a DsFileReader object, see matlab.io.datastore.DsFileReader.


Determine if File-Reader Object Has Data to Read

Create a file-reader object for a file, check if the file has data to read, and then read the data.

Create a DsFileReader object for airlinesmall.csv.

fr = matlab.io.datastore.DsFileReader('airlinesmall.csv');

Check if the file has data to read using the hasdata method. Then, read the first 1000 characters.

 if hasdata(fr)
    d = read(fr,1000,'SizeMethod','OutputSize','OutputType','char');

Introduced in R2017b