Main Content



Partition file-set object


subfs = partition(fs,n,index)


subfs = partition(fs,n,index) partitions file set fs into the number of parts specified by n and returns the partition corresponding to the index index.

Input Arguments

expand all

Input file-set, specified as a DsFileSet, FileSet, or BlockedFileSet object. To create a DsFileSet object, see To create a FileSet object, see To create a BlockedFileSet object, see

Number of partitions, specified as a positive integer.

Example: 3

Data Types: double

Index, specified as a positive integer.

Example: 1

Data Types: double


Partition File-Set Object and Get One Partition

Create a file-set object, partition the file-set object, and get the files contained in a specified partition.

Create a file-set object for all .mat files in a folder.

folder = fullfile(matlabroot,'toolbox','matlab','demos');  
fs =,'FileExtensions','.mat');

Partition the 40 files into five partitions and obtain the first partition. Then, get the file information of all files in the first partition.

subfsA = partition(fs,5,1) % first 8 files
subfsA_fileInfo = resolve(subfsA)

Obtain the second partition and files information for files in this partition.

subfsB = partition(fs,5,2) % next 8 files
subfsB_fileInfo = resolve(subfsB)


  • Use the NumFiles property of the DsFileSet object to find the number of files in fs and use that number to estimate a reasonable number of partitions for the datastore.

Version History

Introduced in R2017b