Main Content

subset

Create datastore with subset of files

Description

example

ADSsubset = subset(ADS,indices) returns an audio datastore, ADSsubset, which contains a subset of the files in ADS.

Examples

collapse all

subset creates an audio datastore containing a subset of the files of the original datastore.

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 34 more
                              }
                     Folders: {
                              '/mathworks/devel/bat/Bdoc23b/build/matlab/toolbox/audio/samples'
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
                      Labels: {}
      SupportedOutputFormats: ["wav"    "flac"    "ogg"    "opus"    "mp4"    "m4a"]
         DefaultOutputFormat: "wav"

Create a logical vector indicating whether the file names in the audio datastore contain 'Guitar'.

fileContainsGuitar = cellfun(@(c)contains(c,'Guitar'),ADS.Files)
fileContainsGuitar = 37x1 logical array

   0
   0
   0
   0
   0
   0
   0
   0
   0
   0
      ⋮

Call subset with the audio datastore and the indices corresponding to the files you want create a new audio datastore from.

ADSsubset = subset(ADS,fileContainsGuitar)
ADSsubset = 
  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/SoftGuitar-44p1_mono-10mins.ogg'
                              }
                     Folders: {
                              '/mathworks/devel/bat/Bdoc23b/build/matlab/toolbox/audio/samples'
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
                      Labels: {}
      SupportedOutputFormats: ["wav"    "flac"    "ogg"    "opus"    "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)
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 34 more
                              }
                     Folders: {
                              '/mathworks/devel/bat/Bdoc23b/build/matlab/toolbox/audio/samples'
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
                      Labels: {}
      SupportedOutputFormats: ["wav"    "flac"    "ogg"    "opus"    "mp4"    "m4a"]
         DefaultOutputFormat: "wav"

Create an audio datastore containing every other file of the original datastore.

indices = 1:2:numel(ADS.Files);
ADSsubset = subset(ADS,indices)
ADSsubset = 
  audioDatastore with properties:

                       Files: {
                              ' .../build/matlab/toolbox/audio/samples/Ambiance-16-44p1-mono-12secs.wav';
                              ' .../toolbox/audio/samples/ChurchImpulseResponse-16-44p1-mono-5secs.wav';
                              ' .../build/matlab/toolbox/audio/samples/Counting-16-44p1-mono-15secs.wav'
                               ... and 16 more
                              }
                     Folders: {
                              '/mathworks/devel/bat/Bdoc23b/build/matlab/toolbox/audio/samples'
                              }
    AlternateFileSystemRoots: {}
              OutputDataType: 'double'
                      Labels: {}
      SupportedOutputFormats: ["wav"    "flac"    "ogg"    "opus"    "mp4"    "m4a"]
         DefaultOutputFormat: "wav"

Input Arguments

collapse all

Specify ADS as an audioDatastore object.

Specify indices as:

  • A vector containing the indices of files to be included in ADSsubset.

  • A logical vector the same length as the number of files in ADS. If specifying indices as a logical vector, true indicates that the corresponding files are included in ADSsubset.

Data Types: double | logical

Output Arguments

collapse all

Subset of audio datastore, returned as an audioDatastore object.

Version History

Introduced in R2018b