Main Content

partition

Partition datastore and return on partitioned portion

Description

example

subADS = partition(ADS,numPartitions,index) partitions datastore ADS into the number of parts specified by numPartitions and returns the partition corresponding to the index.

example

subADS = partition(ADS,'Files',index) partitions the datastore by files and returns the partition corresponding to the file of index index in the Files property.

subADS = partition(ADS,'Files',filename) partitions the datastore by files and returns the partition corresponding to the file specified by filename.

Examples

collapse all

Specify the file path to the audio samples included with Audio Toolbox™. Create an audio datastore that points to the specified folder.

folder = fullfile(matlabroot,'toolbox','audio','samples');
ADS = audioDatastore(folder)
ADS = 
  audioDatastore with properties:

                       Files: {
                              ' .../build/matlab/toolbox/audio/samples/Ambiance-16-44p1-mono-12secs.wav';
                              ' .../matlab/toolbox/audio/samples/AudioArray-16-16-4channels-20secs.wav';
                              ' .../toolbox/audio/samples/ChurchImpulseResponse-16-44p1-mono-5secs.wav'
                               ... and 36 more
                              }
                     Folders: {
                              ' .../filer/batfs1904-0/Bdoc24a.2528353/build/matlab/toolbox/audio/samples'
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
           OutputEnvironment: 'cpu'
                      Labels: {}
      SupportedOutputFormats: ["wav"    "flac"    "ogg"    "opus"    "mp3"    "mp4"    "m4a"]
         DefaultOutputFormat: "wav"

Partition the datastore into three parts.

subADS1 = partition(ADS,3,1)
subADS1 = 
  audioDatastore with properties:

                       Files: {
                              ' .../build/matlab/toolbox/audio/samples/Ambiance-16-44p1-mono-12secs.wav';
                              ' .../matlab/toolbox/audio/samples/AudioArray-16-16-4channels-20secs.wav';
                              ' .../toolbox/audio/samples/ChurchImpulseResponse-16-44p1-mono-5secs.wav'
                               ... and 10 more
                              }
                     Folders: {
                              ' .../filer/batfs1904-0/Bdoc24a.2528353/build/matlab/toolbox/audio/samples'
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
           OutputEnvironment: 'cpu'
                      Labels: {}
      SupportedOutputFormats: ["wav"    "flac"    "ogg"    "opus"    "mp3"    "mp4"    "m4a"]
         DefaultOutputFormat: "wav"

subADS2 = partition(ADS,3,2)
subADS2 = 
  audioDatastore with properties:

                       Files: {
                              ' .../matlab/toolbox/audio/samples/JetAirplane-16-11p025-mono-16secs.wav';
                              ' .../build/matlab/toolbox/audio/samples/Laughter-16-8-mono-4secs.wav';
                              ' .../matlab/toolbox/audio/samples/MainStreetOne-16-16-mono-12secs.wav'
                               ... and 10 more
                              }
                     Folders: {
                              ' .../filer/batfs1904-0/Bdoc24a.2528353/build/matlab/toolbox/audio/samples'
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
           OutputEnvironment: 'cpu'
                      Labels: {}
      SupportedOutputFormats: ["wav"    "flac"    "ogg"    "opus"    "mp3"    "mp4"    "m4a"]
         DefaultOutputFormat: "wav"

subADS3 = partition(ADS,3,3)
subADS3 = 
  audioDatastore with properties:

                       Files: {
                              ' .../matlab/toolbox/audio/samples/RockGuitar-16-44p1-stereo-72secs.wav';
                              ' .../matlab/toolbox/audio/samples/RockGuitar-16-96-stereo-72secs.flac';
                              ' .../build/matlab/toolbox/audio/samples/SingingAMajor-16-mono-18secs.ogg'
                               ... and 10 more
                              }
                     Folders: {
                              ' .../filer/batfs1904-0/Bdoc24a.2528353/build/matlab/toolbox/audio/samples'
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
           OutputEnvironment: 'cpu'
                      Labels: {}
      SupportedOutputFormats: ["wav"    "flac"    "ogg"    "opus"    "mp3"    "mp4"    "m4a"]
         DefaultOutputFormat: "wav"

Specify the file path to the audio samples included with Audio Toolbox™. Create an audio datastore that points to the specified folder.

folder = fullfile(matlabroot,'toolbox','audio','samples');
ADS = audioDatastore(folder);

Get the default number of partitions for ADS.

n = numpartitions(ADS);

Partition the datastore into the default number of partitions and return the datastore corresponding to the first partition.

subADS = partition(ADS,n,1);

Read the data in subADS.

while hasdata(subADS)
    data = read(subADS);
end

Specify the file path to the audio samples included with Audio Toolbox™. Create an audio datastore that points to the specified folder.

folder = fullfile(matlabroot,'toolbox','audio','samples');
ADS = audioDatastore(folder);

Partition the datastore by files and return the part corresponding to the second file. subds contains one file.

subds = partition(ADS,'Files',2)
subds = 
  audioDatastore with properties:

                       Files: {
                              ' .../matlab/toolbox/audio/samples/AudioArray-16-16-4channels-20secs.wav'
                              }
                     Folders: {
                              ' .../filer/batfs1904-0/Bdoc24a.2528353/build/matlab/toolbox/audio/samples'
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
           OutputEnvironment: 'cpu'
                      Labels: {}
      SupportedOutputFormats: ["wav"    "flac"    "ogg"    "opus"    "mp3"    "mp4"    "m4a"]
         DefaultOutputFormat: "wav"

Partition a datastore to facilitate parallel access over the available parallel pool of workers.

Specify the file path to the audio samples included with Audio Toolbox™. Create an audio datastore that points to the specified folder.

folder = fullfile(matlabroot,'toolbox','audio','samples');
ADS = audioDatastore(folder);

Return an estimate for a reasonable number of partitions for parallel processing, given the current parallel pool.

pool = gcp;
n = numpartitions(ADS,pool);

Partition the audio datastore and read the data in each part.

parfor ii = 1:n
    subds = partition(ADS,n,ii);
    while hasdata(subds)
        data = read(subds);
    end
end

Input Arguments

collapse all

Audio datastore, specified as an audioDatastore object.

Number of partitions, specified as a positive integer. Use numpartitions to estimate a reasonable value for numPartitions.

Data Types: double

Index of sub-datastore, specified as a positive integer in the range [1,numPartitions].

Data Types: double

File name, specified as a character vector.

The value of filename must match exactly the file name contained in the Files property of the datastore.

Data Types: char

Output Arguments

collapse all

Output audio datastore, returned as an audioDatastore object.

Version History

Introduced in R2018b