Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: How can I do this in MATLAB? (Possibilities)
Date: Sat, 31 Jan 2009 14:19:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <gm1mkl$eq0$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 1233411541 15168 172.30.248.37 (31 Jan 2009 14:19:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 31 Jan 2009 14:19:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1477385
Xref: news.mathworks.com comp.soft-sys.matlab:515126


Hello,
Say I have an vector a=[0 0 0]; I want all the possibilities of switching the zeros to numbers. For example I want a function that grants the following as output:

Number of zeros: 3
Max number sum: 3

Output:
0 0 0
1 0 0
0 1 0
0 0 1
2 0 0
1 1 0
0 2 0
0 1 1
0 0 2
1 0 1
3 0 0
2 1 0
2 0 1
0 3 0
1 2 0
0 2 1
0 0 3
0 1 2
1 0 2
1 1 1

Or at least get the answer for maximum sum of 1:
0 0 0
1 0 0
0 1 0
0 0 1

I think I can do it using dec2bin and some other operations but it would be extremely inefficient.
Any help is welcome!