MATLAB: Determine which cells contain elements of another cell

match cellsMATLAB

I have the following cell aray:
fileNames = [{'.'}, {'..'}, {'1.bin'}, {'1_Report.txt'}, {'2.bin'}, {'2_Report.txt'}, {'3.bin'}, {'3_Report.txt'}, {'4.bin'}];
I want to determine which *.bin files have a cooresponding *.txt file, so the final result would be:
processedFiles = [{'1.bin'}, {'2.bin'}, {'3.bin'}];
or
processedIndex = [3, 5, 7];
This seems like it should be easy but i'm struggling and hoping for some help in the right direction
Mike

Best Answer

Here's a simpler solution than my first proposal.
fileNames = [{'.'}, {'..'}, {'1.bin'}, {'1_Report.txt'}, {'2.bin'}, {'2_Report.txt'}, {'3.bin'}, {'3_Report.txt'}, {'4.bin'}];
binNums = regexp([fileNames{contains(fileNames, '.bin')}], '\d+', 'match');
txtNums = regexp([fileNames{contains(fileNames, '_Report.txt')}], '\d+', 'match');
hasMatch = ismember(binNums, txtNums);
processedFiles = strcat(binNums(hasMatch), '.bin'); % = [{'1.bin'}, {'2.bin'}, {'3.bin'}];
processedIndex = find(ismember(fileNames, processedFiles)); % = [3, 5, 7];