How to save output of a recursive function
Mostrar comentarios más antiguos
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 3x27.
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
end
for i=1:3
X(n)= A(n,i);
comb(n+1,X,A);
end
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!