Path: news.mathworks.com!not-for-mail
From: "Yang Zhang" <zhyang99@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to generate a random data?
Date: Fri, 27 Jul 2007 05:08:01 +0000 (UTC)
Organization: Univ Texas
Lines: 19
Message-ID: <f8bujg$6n6$1@fred.mathworks.com>
References: <ef5ede4.-1@webcrossing.raydaftYaTP>
Reply-To: "Yang Zhang" <zhyang99@hotmail.com>
NNTP-Posting-Host: webapp-00-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1185512881 6886 172.30.248.35 (27 Jul 2007 05:08:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 27 Jul 2007 05:08:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1058988
Xref: news.mathworks.com comp.soft-sys.matlab:421327



"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