%% Split Labels in Random Order
% 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)

%
% Create two new datastores from the files in ADS by randomly drawing from each label. The first datastore, ADS1, contains two random files with the A label and two random files with the B label. ADS2 contains the remaining files from each label.

[ADS1,ADS2] = splitEachLabel(ADS,2,'randomized')

%
% Copyright 2018 The MathWorks, Inc.