MATLAB: Combinations of values of array of vectors (of different lengths) but ONLY in order the vectors appear in the array

combinationrecursion

Hi, I'm trying to transcribe protein letters to DNA codons. I have a single row array that looks like:
[N1 N2 N3 N4 ...]
Each vector looks like:
N1 = {'UUU' 'UUG' 'UUC'} or
N2 = {'AUU' 'AUG' 'AUC' 'AAU' 'AAG'}
(number of cells can vary from 1 to 6)
I want every combination of the values of these vectors BUT only in the order they appear in the main [N1 N2] vector. For example, 'UUU AUU' and "UUU AUG' are desirable but 'AUU UUU' and 'AUG UUU' are NOT.
Also every combination must contain a value from each vector. So if the array has 20 'N' vectors then each combination needs 20 'three letter' strings.
I'm not much of a coder and I've ended up in a useless mess of nested loops. I think this is a problem for recursion but I'm stuck 🙁
Your help and time are greatly appreciated! 🙂 Also please let me know if I can clarify anything.
edit: put examples in matlab syntax

Best Answer

If I understand your question right, I think that your problem is one of creating unique combinations out of unequal length vectors. Perhaps you should look up the combvec function.
As a sample, when I run the following code snippet:
x = [1,2];
y = [4,5,6];
z = [8,9];
combvec(x,y,z)
I get the following answer (read column-wise of course)
ans =
1 2 1 2 1 2 1 2 1 2 1 2
4 4 5 5 6 6 4 4 5 5 6 6
8 8 8 8 8 8 9 9 9 9 9 9
To me this sounds like exactly what you require.
Good Luck!