Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How can I do this in MATLAB? (Possibilities)
Date: Sat, 31 Jan 2009 15:45:03 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 37
Message-ID: <gm1rlv$4jg$1@fred.mathworks.com>
References: <gm1mkl$eq0$1@fred.mathworks.com> <4034274c-ad64-40f0-a46d-7b8fbedb3094@g1g2000pra.googlegroups.com> <gm1q8t$5ap$1@fred.mathworks.com> <gm1qm2$1b2$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1233416703 4720 172.30.248.37 (31 Jan 2009 15:45:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 31 Jan 2009 15:45:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 688530
Xref: news.mathworks.com comp.soft-sys.matlab:515143


A brute force approach would be to find all the permutations (NOT combinations) then filter it.

http://www.mathworks.com/matlabcentral/fileexchange/11462


vct = npermutek([0 1 2 3],3);
idx = find(sum(ans,2)<=3);
vct = vct(idx,:)

vct =

     0     0     0
     0     0     1
     0     0     2
     0     0     3
     0     1     0
     0     1     1
     0     1     2
     0     2     0
     0     2     1
     0     3     0
     1     0     0
     1     0     1
     1     0     2
     1     1     0
     1     1     1
     1     2     0
     2     0     0
     2     0     1
     2     1     0
     3     0     0





8[T[ia_[Thy^ThXgTr\lraLXgbrVrU@brbrTX!XrgcUT\T`-rbZ_yV`3cbb