Path: news.mathworks.com!not-for-mail
From: "Sadik " <sadik.hava@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Generating Random numbers
Date: Thu, 2 Jul 2009 13:34:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 74
Message-ID: <h2id09$sbh$1@fred.mathworks.com>
References: <d639c2c7-c672-4177-b89b-5c584755dabc@x5g2000yqk.googlegroups.com> <8f91f9c6-aacc-4e38-92d7-1608eeb61076@a7g2000yqk.googlegroups.com>
Reply-To: "Sadik " <sadik.hava@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246541641 29041 172.30.248.35 (2 Jul 2009 13:34:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 2 Jul 2009 13:34:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1666517
Xref: news.mathworks.com comp.soft-sys.matlab:552380


B = A(indicesOf4000,:);

should give you the matrix. 

In order to write to the text file, you need to do the following:

fid = fopen('C:\4000.txt','w');
fprintf(fid,'%d %d %d %d %d %d %d \n',A(indicesOf4000,:));
fclose(fid);

You could open the file using wordpad and you will hopefully see the numbers in a regular manner.

Hope this helps.


Deivy <deivy71@gmail.com> wrote in message <8f91f9c6-aacc-4e38-92d7-1608eeb61076@a7g2000yqk.googlegroups.com>...
> Hi Sadik & John,
> Thank you for your replies.
> 
> Sadik,
> when such a solution exists how do I extract to another matrix or wite
> to a text file.
> 
> Thank you,
> Regards,
> Deivy
> 
> 
> 
> 
> 
> On Jul 2, 2:45?pm, "John D'Errico" <woodch...@rochester.rr.com> wrote:
> > Deivy <deiv...@gmail.com> wrote in message <1602c78c-e855-4e3b-a483-4fa3ecba6...@h8g2000yqm.googlegroups.com>...
> >
> > > Hi Sadik,
> > > Thanks for the reply.
> > > The choice of 3000 was accidental and it made the case bit easier.
> >
> > > What if the total is 4000, where it is not directly related to any of
> > > the numbers 500 and 600, and how do I do that.
> >
> > You should recognize that this is not possible in some
> > circumstances, and certainly will not be a random set
> > of numbers.
> >
> > For example, write the number 2401 as the sum of ANY
> > size set of numbers in the range [500,600]. It cannot
> > be done.
> >
> > Or, write 2500 as such a sum? It turns out there is only
> > one such solution, 2500 = 500 + 500 + 500 + 500 + 500.
> > You may not think of this solution as a random set.
> >
> > Regardless, even if a solution exists that is not unique,
> > it is not random in the common sense of the word, since
> > given the first n-1 members of the set, the last member
> > is uniquely determined to meet the sum criterion.
> >
> > If you still insist on finding a random looking set of
> > numbers that satisfy your sum constraint, use a simple
> > logic:
> >
> > How many terms will the sum be composed of?
> >
> > 7*500 = 3500, and 8*500 = 4000.
> > 7*600 = 4200
> >
> > Therefore, the sum must be composed of 7 numbers in
> > that range.
> >
> > ?x = 500 + 100*rand(1,7);
> > ?x = x * 4000/sum(x);
> >
> > John