Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!d10g2000yqh.googlegroups.com!not-for-mail
From: Eyal <efleminge@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Identifying repeating pattern in a vector
Date: Tue, 3 Nov 2009 05:50:13 -0800 (PST)
Organization: http://groups.google.com
Lines: 28
Message-ID: <e09c467a-b65f-4636-bb80-67ba02bff5da@d10g2000yqh.googlegroups.com>
NNTP-Posting-Host: 207.232.27.5
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1257256213 10473 127.0.0.1 (3 Nov 2009 13:50:13 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 3 Nov 2009 13:50:13 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: d10g2000yqh.googlegroups.com; posting-host=207.232.27.5; 
	posting-account=hSLB2QoAAAADSPpo9LOgQV2KWvtFKXMI
User-Agent: G2/1.0
X-HTTP-Via: 1.0 eltixpro2:3128 (squid/2.7.STABLE6)
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 
	2.0.50727),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:582041


Hi

I have a function running a loop where a value is added to a vector at
each iteration. So, for example, if the vector is x, it could look
like:

Iteration 1: x=[1]
Iteration 2: x=[1,3]
Iteration 3: x=[1,3,2]
Iteration 4: x=[1,3,2,6]
Iteration 5: x=[1,3,2,6,2]
Iteration 6: x=[1,3,2,6,2,6]
Iteration 7: x=[1,3,2,6,2,6,2]

and so on.

As can be seen in the example above, at some point a repeating pattern
of values may appear in x; this indicates the function has entered an
infinite loop. I would like to be able to catch the pattern, say for
example after 3 repeats. In the example above, that would be when the
last 6 values of x are [2,6,2,6,2,6]; however, I do not know the
values in advance, nor do I know the length of the repeating pattern
(e.g. it could be [2,4,6,3,2,4,6,3,2,4,6,3]), though for practical
purposes three values should be sufficient to catch this error.

Can anyone suggest a way to identify this repeating pattern?

Thx