partition
Partition datastore and return on partitioned portion
Syntax
Description
partitions datastore subADS = partition(ADS,numPartitions,index)ADS into the number of parts specified by
numPartitions and returns the partition corresponding to the
index.
Examples
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: {
' .../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: {
' .../Bdoc25b.2988451/build/runnable/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: {
' .../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: {
' .../Bdoc25b.2988451/build/runnable/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';
' .../runnable/matlab/toolbox/audio/samples/Laughter-16-8-mono-4secs.wav';
' .../matlab/toolbox/audio/samples/MainStreetOne-16-16-mono-12secs.wav'
... and 10 more
}
Folders: {
' .../Bdoc25b.2988451/build/runnable/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';
' .../matlab/toolbox/audio/samples/SingingAMajor-16-mono-18secs.ogg'
... and 10 more
}
Folders: {
' .../Bdoc25b.2988451/build/runnable/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: {
' .../Bdoc25b.2988451/build/runnable/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
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
Output audio datastore, returned as an audioDatastore
object.
Version History
Introduced in R2018b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)