Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: looking at all possible combinations Date: Sat, 10 Jul 2010 06:22:05 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 38 Message-ID: <i193id$3cn$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: <HIDDEN> NNTP-Posting-Host: webapp-05-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1278742925 3479 172.30.248.35 (10 Jul 2010 06:22:05 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sat, 10 Jul 2010 06:22:05 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:651939 "Ozge Taskan" <lordgy@yahoo.com> wrote in message <i18p6g$kri$1@fred.mathworks.com>... > 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? > > thank you very much in advance. - - - - - - - - - - You can accomplish that using numbers with mixed bases. That is, start with the number 0 and count by ones up to 648-1. For each one of these numbers, compute the nine digits that would represent that number with the nine different bases 2, 2, 1, 3, 3, 3, 1, 2, 3. If 1 is added to each of these digits, they can be used as indices into a cell array containing all the number sets possible for each digit: the first digit can be 1 or 4, the second one also 1 or 4, the third one only 4, the fourth 1, 2, or 3, etc. For example, the number N = 556 can be represented in the mixed bases above by: 1 1 0 1 0 2 0 1 1 since 556 = ((((((((1)*2+1)*1+0)*3+1)*3+0)*3+2)*1+0)*2+1)*3+1 Suppose v = [2 2 1 3 3 3 1 2 3] contains the nine bases, that is the nine lengths in the cell array. Suppose N = 556. You can obtain these nine digits with a for-loop: q = N; for k = 9:-1:1 r = mod(q,v(k)); q = (q-r)/v(k); % At this point use r+1 as an index into the k-th cell array % of possible numbers and place result in a matrix, X(N+1,k) end You would have an outer for-loop going through all the possible values of N from 0 to 647. I'll let you work out the rest of the details. The only difference between the above and converting a number to decimal or binary digits is that the bases are variable in this situation. Roger Stafford