%% Split by Number of 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,'FileExtensions','.wav');

%
% Add the label A to the first half of the files, and the label B to the second half. If there are 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)

%
% Split ADS into two datastores, ADS1 and ADS2. Specify that ADS1 contains four of each label and its corresponding file. ADS2 contains the remaining labels and corresponding files. Call countEachLabel to confirm that ADS1 contains four files labeled A and four files labeled B, and that ADS2 contains the remaining labels.

[ADS1,ADS2] = splitEachLabel(ADS,4)

ADS1count = countEachLabel(ADS1)
ADS2count = countEachLabel(ADS2)

%
% Copyright 2018 The MathWorks, Inc.