Path: news.mathworks.com!not-for-mail
From: "Rui Yang" <rui.yang@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to generate a random data?
Date: Fri, 27 Jul 2007 05:24:09 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 23
Message-ID: <f8bvhp$jqd$1@fred.mathworks.com>
References: <ef5ede4.-1@webcrossing.raydaftYaTP> <f8bujg$6n6$1@fred.mathworks.com>
Reply-To: "Rui Yang" <rui.yang@mathworks.com>
NNTP-Posting-Host: webapp-01-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1185513849 20301 172.30.248.36 (27 Jul 2007 05:24:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 27 Jul 2007 05:24:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1067979
Xref: news.mathworks.com comp.soft-sys.matlab:421329



"Yang Zhang" <zhyang99@hotmail.com> wrote in message <f8bujg$6n6$1@fred.mathworks.com>...
> "Rui Yang" <rui.yang@mathworks.com> wrote in message <ef5ede4.-1@webcrossing.raydaftYaTP>...
> > I want to generate a random sequence. For example(1,2,3,4).The probability distributing of each element is (20%, 20%, 20%, 40%). How to realize it in Matlab?
> 
> 
> 
> ===============
> Hi,
> 
> A simple but not wise way is:
> 
> x = rand(1,1000);
> y = 4*ones(1,1000);
> y(find(x<-0.6)) = 1;
> y(find(x>-0.6 || x < -0.2)) = 2;
> y(find(x>-0.2 || x < 0.2)) = 3;
> 
> HTH
> 
> Yang

Thanks, It is a good way to get it.