Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: looking at all possible combinations
Date: Sat, 10 Jul 2010 09:03:05 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 36
Message-ID: <i19d09$s9a$1@fred.mathworks.com>
References: <hsrjq4$9t0$1@fred.mathworks.com> <hsrpj9$2lg$1@fred.mathworks.com> <hsrrsd$o20$1@fred.mathworks.com> <i18p6g$kri$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1278752585 28970 172.30.248.38 (10 Jul 2010 09:03:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 10 Jul 2010 09:03:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:651947

"Ozge Taskan" <lordgy@yahoo.com> wrote in message <i18p6g$kri$1@fred.mathworks.com>...
> "Matt Fig" <spamanon@yahoo.com> wrote in message <hsrrsd$o20$1@fred.mathworks.com>...
> > I see.  If Jos is correct, then you can also do this with a slight modification of the solution I gave earlier.
> > 
> > 
> > [m,n] = size(A);
> > Rr = npermutek(1:n,m);  % The "Row-Rank" matrix.
> > G = A((Rr-1)*m+repmat(1:m,n^m,1));
> > 
> > IIRC, COMBN and NPERMUTEK do the same thing using different methods.
> 
> Hi,
> I would like to ask something related to same thing.
> If we have 9 numbers and we would like to assign one of the numbers below how can we look at each possibilities for example 
> 1st number can be 1 or 4
> 2nd number can be 1 or 4 
> 3rd number can be 4 
> 4th number can be 1 or 2 or 3 
> 5th number can be 1 or 2 or 3 
> 6th number can be 1 or 2 or 3 	
> 7th number can be 3	
> 8th number can be 2 or 3	
> 9th number can be 1 or 2 or 3 
> how can we construct 2*2*1*3*3*3*1*2*3(648) numbers?
> 

You can use NDGRID as following:

c={[1 4] [1 4] 4 [1 2 3] [1 2 3] [1 2 3] 3 [2 3] [1 2 3]}

n = length(c);
[c{:}]=ndgrid(c{:});
c=cat(n+1,c{:});
c = reshape(c,[],n) % 648 combinations of 9 numbers

% Bruno