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
Partition Datastore into Specific Number of Parts
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: { ' .../Bdoc24b.2679053/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: { ' .../Bdoc24b.2679053/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: { ' .../Bdoc24b.2679053/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: { ' .../Bdoc24b.2679053/build/runnable/matlab/toolbox/audio/samples' } AlternateFileSystemRoots: {} OutputDataType: 'double' OutputEnvironment: 'cpu' Labels: {} SupportedOutputFormats: ["wav" "flac" "ogg" "opus" "mp3" "mp4" "m4a"] DefaultOutputFormat: "wav"
Partition Datastore into Default Number of Parts
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
Partition Datastore by Files
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: { ' .../Bdoc24b.2679053/build/runnable/matlab/toolbox/audio/samples' } AlternateFileSystemRoots: {} OutputDataType: 'double' OutputEnvironment: 'cpu' Labels: {} SupportedOutputFormats: ["wav" "flac" "ogg" "opus" "mp3" "mp4" "m4a"] DefaultOutputFormat: "wav"
Number of Partitions for Parallel Datastore Access
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
ADS
— Audio datastore
audioDatastore
object
Audio datastore, specified as an audioDatastore
object.
numPartitions
— Number of partitions
positive integer
Number of partitions, specified as a positive integer. Use numpartitions
to estimate a reasonable value for numPartitions
.
Data Types: double
index
— Index of sub-datastore
positive integer
Index of sub-datastore, specified as a positive integer in the range
[1,
.numPartitions
]
Data Types: double
filename
— File name
character vector
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
subADS
— Output audio datastore
audioDatastore
object
Output audio datastore, returned as an audioDatastore
object.
Version History
Introduced in R2018b
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- 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)