Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Creating array with specific sum
Date: Fri, 22 Jul 2011 11:14:11 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 31
Message-ID: <j0bm23$ci$1@newscl01ah.mathworks.com>
References: <j0bgc5$g05$1@newscl01ah.mathworks.com> <j0blbi$s26$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1311333251 402 172.30.248.35 (22 Jul 2011 11:14:11 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 22 Jul 2011 11:14:11 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2958486
Xref: news.mathworks.com comp.soft-sys.matlab:737155

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j0blbi$s26$1@newscl01ah.mathworks.com>...
> "Mohd" wrote in message <j0bgc5$g05$1@newscl01ah.mathworks.com>...
> > Hi,
> > 
> > I want to create a 1xn array, that come out with specific total. For example, given the summation of array is 20. Then, I want to create an array with 1x5 matrix. The answer might be as follow:
> > [5 7 3 2 3], or [2 4 1 7 6] or any other 1x5 matrix with total 20.
> > 
> 
> The bellow will create exactly the array as your requirement, however I'm almost sure it's not what you really want.
> 
> >> a=rand(1,4)
> 
> a =
> 
>     0.8147    0.9058    0.1270    0.9134
> 
> >> a(end+1)=20-sum(a)
> 
> a =
> 
>     0.8147    0.9058    0.1270    0.9134   17.2391
> 
> Up to you to describe correctly the constraints, requirement that are still missing. 
> 
> Bruno

Thank you Bruno,

I want to create random +ve integer 1xn array with predefined summation.

Thanks again