This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Datastore with custom file reader


FileDatastore objects are associated with large collections of custom format files where the collection does not necessarily fit in memory. You can use the fileDatastore function or the datastore function to create a FileDatastore object. Once the object is created, you can specify FileDatastore properties, and use functions that access and manage the data.


Create FileDatastore objects using the fileDatastore function or the datastore function.


expand all

Files included in the datastore, resolved as a cell array of character vectors, where each character vector is a full path to a file. The location argument in the fileDatastore and datastore functions defines Files when the datastore is created.

Example: {'C:\dir\data\file1.ext';'C:\dir\data\file2.ext'}

Example: 'hdfs:///data/*.mat'

Data Types: char | cell

Function that reads the file data, specified as a function handle. The function must take a file name as input, and then output the corresponding file data. For example, if customreader is the specified function to read the file, then it must have a signature similar to the following:

function data = customreader(filename)
If there is more than one output argument, then only the first is used and the rest are ignored.

Example: @customreader

Data Types: function_handle

This property is read-only.

Vertically concatenable flag, specified as true, false, 0, or 1.


Indicates that multiple reads of the FileDatastore object return uniform data that is vertically concatenable.

When the UniformRead property is true:

  • The ReadFcn must return data that is vertically concatenable, else the readall method returns an error.

  • The data type of the output of tall is the same as the underlying data type of the output from the ReadFcn.


Indicates that multiple reads of the FileDatastore object do not return uniform data that is vertically concatenable.

When the UniformRead property is false:

  • readall returns a cell array.

  • tall returns a tall cell array.

Data Types: logical | double

Object Functions

hasdataDetermine if data is available to read
numpartitionsNumber of datastore partitions
partitionPartition a datastore
previewSubset of data in datastore
readRead data in datastore
readallRead all data in datastore
resetReset datastore to initial state


expand all

Create a datastore for files in the MATLAB® demos folder that have a .mat extension.

fds = fileDatastore(fullfile(matlabroot,'toolbox','matlab','demos'),'ReadFcn',@load,'FileExtensions','.mat')
fds = 

  FileDatastore with properties:

      Files: {
             ' ...\matlab\toolbox\matlab\demos\accidents.mat';
             ' ...\matlab\toolbox\matlab\demos\airfoil.mat';
             ' ...\matlab\toolbox\matlab\demos\airlineResults.mat'
              ... and 35 more
    ReadFcn: @load


  • fileDatastore is designed to read data from files and reads one complete file at a time. To read a subset of data from a large file or to read from a data stream, you must build your own custom datastore. For more information, see Develop Custom Datastore.

Introduced in R2016a

Was this topic helpful?