Main Content

combine

Combine data from multiple datastores

Description

ADSnew = combine(ADS1,ADS2,...,ADSN) combines two or more datastores by horizontally concatenating the data returned by read of the input datastores.

example

Examples

collapse all

Create a datastore that maintains parity between the audio of the underlying datastores. Create two separate audio datastores, and then create a combined datastore representing the two underlying datastores.

Create a datastore ads1 that points to the audio files included with Audio Toolbox.

folder = fullfile(matlabroot,'toolbox','audio','samples');
ads1 = audioDatastore(folder);

Create a second datastore ads2 by adding noise to the audio in the ads1.

ads2 = transform(ads1,@(x) x + 0.01*randn(size(x)) );

Create a combined datastore from ads1 and ads2.

adsCombined = combine(ads1,ads2);

Read the first pair of audio files from the combined datastore. Each read operation on this combined datastore returns a pair of audio signals in a 1-by-2 cell array and a pair of info structs in a 1-by-2 cell array.

[dataOut,infoOut] = read(adsCombined)
dataOut=1×2 cell array
    {539648x1 double}    {539648x1 double}

infoOut=1×2 cell array
    {1x1 struct}    {1x1 struct}

Plot the spectrograms of the first channels from both audio signals.

figure(1)
spectrogram(dataOut{1},hamming(512),256,512,infoOut{1}.SampleRate,'yaxis')
title('Original Data')

Figure contains an axes object. The axes object with title Original Data, xlabel Time (s), ylabel Frequency (kHz) contains an object of type image.

figure(2)
idx = size(dataOut,2)/2+1;
spectrogram(dataOut{2},hamming(512),256,512,infoOut{2}.SampleRate,'yaxis')
title('Noised Data')

Figure contains an axes object. The axes object with title Noised Data, xlabel Time (s), ylabel Frequency (kHz) contains an object of type image.

Input Arguments

collapse all

Audio datastores to combine, specified as two or more comma separated audioDatastore objects.

Output Arguments

collapse all

New audio datastore with combined data, returned as a matlab.io.datastore.CombinedDatastore object.

Calling read on the combined datastore returns a cell array containing the output of calling read on the individual datastores.

Version History

Introduced in R2019a