partition

Partition datastore and return on partitioned portion

Syntax

subADS = partition(ADS,numPartitions,index)
subADS = partition(ADS,'Files',index)
subADS = partition(ADS,'Files',filename)

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 26 more
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
                      Labels: {}

Partition the datastore into three parts.

subADS1 = partition(ADS,3,1)
subADS2 = partition(ADS,3,2)
subADS3 = partition(ADS,3,3)
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 7 more
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
                      Labels: {}


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-24-96-stereo-63secs.wav'
                               ... and 7 more
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
                      Labels: {}


subADS3 = 

  audioDatastore with properties:

                       Files: {
                              ' .../matlab/toolbox/audio/samples/RockGuitar-16-96-stereo-72secs.flac';
                              ' .../build/matlab/toolbox/audio/samples/SoftGuitar-44p1_mono-10mins.ogg';
                              ' .../build/matlab/toolbox/audio/samples/SpeechDFT-16-8-mono-5secs.wav'
                               ... and 6 more
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
                      Labels: {}

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'
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
                      Labels: {}

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);
Starting parallel pool (parpool) using the 'local' profile ...
Connected to the parallel pool (number of workers: 6).

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.

Introduced in R2018b