Asked by raj singh
on 19 Apr 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.

*No products are associated with this question.*

Answer by Jan Simon
on 19 Apr 2013

Accepted answer

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?

raj singh
on 19 Apr 2013

superb, thank you very very much....its working fast

Answer by Andrei Bobrov
on 19 Apr 2013

Edited by Andrei Bobrov
on 19 Apr 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

Show 1 older comment

raj singh
on 19 Apr 2013

but its combine all row in single row, its nt my prob, my prob is

A=[1 6]; B=[2 3 4]; C=[8 9];

and i want:

comb=1 2 8, 1 2 9, 1 3 8, 1 3 9, ........., 6 4 8,6 4 9

but now i solved my prob with "allcomb" its working superb

Andrei Bobrov
on 19 Apr 2013

see the code before `% ADD` :)

raj singh
on 20 Apr 2013

sorry, its also working for comb, thanks

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 1 Comment

## Jan Simon (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/72718#comment_144202

We cannot generalize your program, we we do not see it. So please post your code, when you want us to help.