%% Include and Exclude Specified Labels

% Copyright 2018 The MathWorks, Inc.

%%
% Specify the file path to the audio samples included with Audio
% Toolbox(TM). Create an audio datastore that points to the specified
% folder.
%

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

%%
% Add the label |A| to the first half of the files, and the label |B| to
% the second half. If there is an odd number of files, assign the extra
% file the label |B|. Call |countEachLabel| to confirm that half of the
% files are labeled |A| and half the files are labeled |B|.
%

labels = [repmat({'A'},1,floor(numel(ADS.Files)/2)), ...
          repmat({'B'},1,ceil(numel(ADS.Files)/2))];
ADS.Labels = labels;

countEachLabel(ADS)

%%
% Create two new datastores from the files in |ADS|, including only the
% files with the |A| label. |ADS1| contains the first 70% of files with the
% |A| label, and |ADS2| contains the remaining 30% of labels with the |A|
% label.
%

[ADS1,ADS2] = splitEachLabel(ADS,0.7,'Include','A')

%%
% Equivalently, you can split only the |A| label by excluding the |B|
% label.
%

[ADS1,ADS2] = splitEachLabel(ADS,0.7,'Exclude','B')