Effacer les filtres
Effacer les filtres

combination of numbers which is not in matrix form

2 vues (au cours des 30 derniers jours)
raj singh
raj singh le 19 Avr 2013
A=[1 6]; B=[2 3 4]; C=[8 9];
i want:
comb=1 2 8, 1 2 9, 1 3 8, 1 3 9, ........., 6 4 8,6 4 9
i m using for loop for this program but i increase more number of element then my program does not work, its go went to infinity. pls help me for generlise program or any command for this types of problem.
  1 commentaire
Jan
Jan le 19 Avr 2013
We cannot generalize your program, we we do not see it. So please post your code, when you want us to help.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 19 Avr 2013
Did you search in the FileExchange already? This would be a good idea before asking the forum. What about http://www.mathworks.com/matlabcentral/fileexchange/10064-allcomb?
  1 commentaire
raj singh
raj singh le 19 Avr 2013
superb, thank you very very much....its working fast

Connectez-vous pour commenter.

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 19 Avr 2013
Modifié(e) : Andrei Bobrov le 19 Avr 2013
A=[1 6]; B=[2 3 4]; C=[8 9];
Use function fullfact from Statistics Toolbox.
for your case:
t = {A,B,C};
k = cellfun(@numel,t);
ii = fullfact(k);
idx = bsxfun(@plus,ii,cumsum(k) - k);
s = [t{:}];
comb = s(idx);
comb = reshape(sortrows(comb)',1,[]); % ADD
  4 commentaires
Andrei Bobrov
Andrei Bobrov le 19 Avr 2013
see the code before % ADD :)
raj singh
raj singh le 20 Avr 2013
sorry, its also working for comb, thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by