Given a matrix A, I have to make all possible combinations of entries of A such that only one number is selected from each row. I have made the following recursive program which is running successfully. But I am not able to save the output vector X. So, for example in the following matrix A, there will be 27 such combinations, I want to save them in matrix of order 3×27.
A=[3 4 0;2 3 7;45 7 0]n=1;X=zeros(3,1);comb(n, X, A); %function to calculate all combinations.
function X =comb(n,X, A)if (n>3) X return endfor i=1:3 X(n)= A(n,i); comb(n+1,X,A);endend
Best Answer