Main Content

hasdata

Class: matlab.io.datastore.DsFileReader
Namespace: matlab.io.datastore

Determine if data is available to read

Syntax

tf = hasdata(fr)

Description

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.

Examples

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');
 end

Version History

Introduced in R2017b