samer@4: function Z=join(X,Y) samer@4: % join - Cartesian product of two arrays samer@4: % samer@4: % join :: [[N,M]], [[L,P]] -> [[N*L,M+P]]. samer@4: % samer@4: % The result contains every pairing of rows from the two arguments samer@4: samer@4: %Z=[repmat(X,size(Y,1),1) kron(Y,ones(size(X,1),1))]; samer@4: samer@4: % this is probably faster (no multiplications!) samer@4: m=size(X,1); n=size(Y,1); samer@4: Z=[repmat(X,n,1) Y(repmat(1:n,m,1),:)];