MATLAB: Combining multiple wav files into one multichannel matrix

audioreadwav. files

Having a bunch of stereo wav files with the structure:
036a.wav, 036b.wav, 036c.wav ...
037a.wav, 037b.wav, 037c.wav ...
...
I wish to load them one by one and concatenate them into a structure so that the files starting with the same number (such as 036) would all be combined into a "multichannel" matrix where the 036a.wav would occupy the first two columns, 036b.wav the column no. 3 and 4, the 036c.wav the colums 5 and 6 etc.
The files 037a.wav … 037b.wav … 037c.wav would follow the same scheme, forming another branch of the struct.
How is this best done in Matlab, please?

Best Answer

Perhaps by something like this:
S = struct();
iS = 0;
Folder = 'C.:\Your\Folder\';
for k = 1:1000
str = sprintf('%03d', k);
if exist(fullfile(Folder, [str, 'a.wav']), 'file')
List = dir(fullfile(Folder, [str, '*.wav']));
Data = cell(1, numel(List));
for iFile = 1:numel(List)
File = fullfile(Folder, List(iFile).name);
Data{iFile} = wavread(File);
end
iS = iS + 1;
S(is).Data = cat(2, Data{:});
S(iS).Key = str;
end
end
This assumes, that all signals have the same length. Otherwise you can pad the signals e.g. by FileExchange: padcat .