MATLAB: How can i pair files with almost the same filename in order to create stereo wav files from mono wav files (ideally as a batch)

batch file processingfilename matchingstereo wavwav

I have a somewhat complicated task I would like to perform that is well beyond my novice level of experience with Matlab. I am using Matlab R2014a.
I use a recording system that creates 2 mono wav files from an acoustic manikin. This is usually done in a batch process across several conditions. The mono wav files are saved in a single directory and are named by the condition. What differentiates the files is the last character in the filename, before the extension – 0 designates the file as left ear, 1 designates right ear.
For example FirstCondition_0.wav FirstCondition_1.wav SecondCondition_0.wav SecondCondition_1.wav ClassicalMusic_0.wav ClassicalMusic_1.wav
What I'd like to do is create a script that can create stereo wav files from the pairs of recordings, as a batch process.
I can do it manually, but after some experiments there are a lot of files.
What I envision is using uigetdir to set the input directory and the output directory, then somehow use a loop to combine the pairs with filename_0.wav becoming (:,1) and filename_1.wav becoming (:,2) for each matched pair.
Does anyone have any suggestions, examples, or ideas?
Thanks!

Best Answer

since you have already the script to combine you can get the list of items by using something like this
list = dir('*.txt');
for i=1:length(list)
Name{i,1} = list(i).name;
end
uScore = cellfun(@(x) strfind(x,'_'),Name);
uScore = num2cell(uScore);
Fname = cellfun(@(x,y) x(1:y-1),Name,uScore,'UniformOutput',false)
unique(Fname)
This will get you the specific names where you can concatenate the '_0.wav' and the _1.wav to it before processing.
so get the list of files, do a for loop for the number of unique filename (before _) and concatenate the _#.wav for your script.