Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!g1g2000pra.googlegroups.com!not-for-mail
From: Rune Allnor <allnor@tele.ntnu.no>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How can I do this in MATLAB? (Possibilities)
Date: Sat, 31 Jan 2009 07:06:29 -0800 (PST)
Organization: http://groups.google.com
Lines: 19
Message-ID: <4034274c-ad64-40f0-a46d-7b8fbedb3094@g1g2000pra.googlegroups.com>
References: <gm1mkl$eq0$1@fred.mathworks.com>
NNTP-Posting-Host: 77.17.190.97
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1233414390 15550 127.0.0.1 (31 Jan 2009 15:06:30 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sat, 31 Jan 2009 15:06:30 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: g1g2000pra.googlegroups.com; posting-host=77.17.190.97; 
	posting-account=VAp5gAkAAAAmkCze5hvZtMeedpZWNthI
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET 
	CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:515131


On 31 Jan, 15:19, "Husam Aldahiyat" <numand...@gmail.com> wrote:
> 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:
...
> I think I can do it using dec2bin and some other operations but it would be extremely inefficient.

Homework?

Seems to be a combination of number theory and combinatorics.
I'd go for a solution that takes the remaining number of
digits and remaning available sum as argument, and recursively
traverses the digit positions.

Since this is a combinatoric problem, don't be expected
if the solution requires an algorithm of high complexity;
something like D^S (or worse) where D is the number of
digits and S is the sum.

Rune