필터 지우기
필터 지우기

combination of numbers which is not in matrix form

조회 수: 2 (최근 30일)
raj singh
raj singh 2013년 4월 19일
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
Jan
Jan 2013년 4월 19일
We cannot generalize your program, we we do not see it. So please post your code, when you want us to help.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2013년 4월 19일
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
raj singh
raj singh 2013년 4월 19일
superb, thank you very very much....its working fast

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 4월 19일
편집: Andrei Bobrov 2013년 4월 19일
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
Andrei Bobrov
Andrei Bobrov 2013년 4월 19일
see the code before % ADD :)
raj singh
raj singh 2013년 4월 20일
sorry, its also working for comb, thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by