MATLAB: Creating a Combination of Multiple Arrays

cell arraysiterationspermutations

I'm having trouble coming up with code to create a combination between two arrays. In my first array, result, I computed the Cartesian product between the two vectors of A.
>> A = {[1 2 3], [4 5 6]}
c = cell(1,numel(A));
[c{:}] = ndgrid(A{:});
result = cell2mat(cellfun(@(v)v(:), c, 'UniformOutput', false) )
resulta =
1 4
2 4
3 4
1 5
2 5
3 5
1 6
2 6
3 6
My second array is:
resultb =
1 3
2 4
I am trying to create iterations between the rows of result and result b. To make it clearer, I want my output array to look like this:
resultc=
1 4 1 3
2 4 1 3
3 4 1 3
1 5 1 3
2 5 1 3
3 5 1 3
1 6 1 3
2 6 1 3
3 6 1 3
1 4 2 4
2 4 2 4
3 4 2 4
1 5 2 4
2 5 2 4
3 5 2 4
1 6 2 4
2 6 2 4
3 6 2 4
How would I create code to achieve this regardless of the sizes of matrices resulta and resultb? Thanks!

Best Answer

combvec(resulta', resultb')'