partition

Class: matlab.io.datastore.DsFileSet
Package: matlab.io.datastore

Partition file-set object

Syntax

subfs = partition(fs,n,index)

Description

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 object, specified as a matlab.io.datastore.DsFileSet object. To create a DsFileSet object, see matlab.io.datastore.DsFileSet.

Number of partitions, specified as a positive integer.

Example: 3

Data Types: double

Index, specified as a positive integer.

Example: 1

Data Types: double

Output Arguments

expand all

Output file-set object, specified as a matlab.io.datastore.DsFileSet object. The output file-set object subfs is a subset of the file-set object fs.

Examples

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 = matlab.io.datastore.DsFileSet(folder,'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)

Tips

  • 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.

Introduced in R2017b