%% Split Labels Several Ways 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 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)

%
% Split ADS into three new datastores, ADS1, ADS2, and ADS3. The first datastore, ADS1, contains the first file with the A label and the first file with the B label. ADS2 contains the next file from each label. ADS3 contains the remaining files from each label. If the percentage applied to a label does not result in a whole number of files, splitEachLabel rounds down to the nearest whole number.

[ADS1,ADS2,ADS3] = splitEachLabel(ADS,1,1)

%
% Call countEachLabel to confirm the correct distribution of labels for each datastore.

countEachLabel(ADS1)
countEachLabel(ADS2)
countEachLabel(ADS3)

%
% Copyright 2018 The MathWorks, Inc.