Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!postnews.google.com!q35g2000hsg.googlegroups.com!not-for-mail
From: Adshak <adshaikh.hipnet@googlemail.com>
Newsgroups: comp.soft-sys.matlab,sci.stat.math
Subject: Growing elements in a vector
Date: Tue, 21 Oct 2008 14:10:22 -0700 (PDT)
Organization: http://groups.google.com
Lines: 48
Message-ID: <6fbe2615-a1f9-46ad-93d4-60500f097e38@q35g2000hsg.googlegroups.com>
NNTP-Posting-Host: 77.101.188.13
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1224623422 10975 127.0.0.1 (21 Oct 2008 21:10:22 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 21 Oct 2008 21:10:22 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: q35g2000hsg.googlegroups.com; posting-host=77.101.188.13; 
	posting-account=CERIfAoAAABmyiyq52uwdWyAPX8ZozK3
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; 
	.NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; .NET CLR 
	3.5.21022; InfoPath.2),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:496637 sci.stat.math:84899


Dear All,

I have a tricky little issue I need to deal with:

I have a vector which goes something like this

vector = [1 2 3 1 2 3 2 3 1 3 2 1 2 3 1 3 2 1 2 3 1 1 3 1 2 1 3 1 2 3
1...];

Please note that the above vector will only have unique elements as
neighbours and hence no repitition of elements.

Now what i want is to cleverly with less computational burden,
consider every element in the vector one by one and replicate the
element as many times as it takes to pass a comparison test against a
randomly drawn variable.

For example, for every unique element 1, 2 and 3 I have a number
between 0 and 1 i.e 0.2, 0.3 and 0.5 respectively.

So how this would work is

1) Consider Vector(1), the element is 1.
2) Draw a Random number. Compare it to 0.2. If less than 0.2, append a
1 after the first 1, else move to next unique element. Continue
appending 1's till random value generated is higher than 0.2
3) If in element 2, compare to 0.3 and if in element 3 compare to 0.5.

finally my output vector should look something like this:

outvector = [1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 1 1 1 1 1 1 1 1
1  2 2 2 2 2 2 3 3 3 3 3 3 3 3 1 1 1 1 3 3 3 3 3.......];


Trying this with for loops for large vectors seems to take a toll on
the speed of computation and I would prefer a quick vector based
solution.


I have been spending a lot of time on this to compute efficiently and
will be really grateful for a solution for this with example code.

Many thanks,

Adshak