<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264837</link>
    <title>MATLAB Central Newsreader - Identifying repeating pattern in a vector</title>
    <description>Feed for thread: Identifying repeating pattern in a vector</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 03 Nov 2009 13:50:13 -0500</pubDate>
      <title>Identifying repeating pattern in a vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264837#691712</link>
      <author>Eyal</author>
      <description>Hi&lt;br&gt;
&lt;br&gt;
I have a function running a loop where a value is added to a vector at&lt;br&gt;
each iteration. So, for example, if the vector is x, it could look&lt;br&gt;
like:&lt;br&gt;
&lt;br&gt;
Iteration 1: x=[1]&lt;br&gt;
Iteration 2: x=[1,3]&lt;br&gt;
Iteration 3: x=[1,3,2]&lt;br&gt;
Iteration 4: x=[1,3,2,6]&lt;br&gt;
Iteration 5: x=[1,3,2,6,2]&lt;br&gt;
Iteration 6: x=[1,3,2,6,2,6]&lt;br&gt;
Iteration 7: x=[1,3,2,6,2,6,2]&lt;br&gt;
&lt;br&gt;
and so on.&lt;br&gt;
&lt;br&gt;
As can be seen in the example above, at some point a repeating pattern&lt;br&gt;
of values may appear in x; this indicates the function has entered an&lt;br&gt;
infinite loop. I would like to be able to catch the pattern, say for&lt;br&gt;
example after 3 repeats. In the example above, that would be when the&lt;br&gt;
last 6 values of x are [2,6,2,6,2,6]; however, I do not know the&lt;br&gt;
values in advance, nor do I know the length of the repeating pattern&lt;br&gt;
(e.g. it could be [2,4,6,3,2,4,6,3,2,4,6,3]), though for practical&lt;br&gt;
purposes three values should be sufficient to catch this error.&lt;br&gt;
&lt;br&gt;
Can anyone suggest a way to identify this repeating pattern?&lt;br&gt;
&lt;br&gt;
Thx</description>
    </item>
    <item>
      <pubDate>Tue, 03 Nov 2009 14:47:02 -0500</pubDate>
      <title>Re: Identifying repeating pattern in a vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264837#691728</link>
      <author>Herve </author>
      <description>&lt;br&gt;
n = size(x,2) &lt;br&gt;
&lt;br&gt;
for a repeating pattern of size 3, then you could use a if function such as &lt;br&gt;
&lt;br&gt;
if x(n) == x (n-3) &amp;&amp; x(n-1) == x(n-4) &amp;&amp; x(n-2) == x(n-5) &lt;br&gt;
&lt;br&gt;
I guess that better matlab's users will find nicer solutions :) </description>
    </item>
    <item>
      <pubDate>Tue, 03 Nov 2009 15:11:02 -0500</pubDate>
      <title>Re: Identifying repeating pattern in a vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264837#691737</link>
      <author>Jos </author>
      <description>Eyal &amp;lt;efleminge@gmail.com&amp;gt; wrote in message &amp;lt;e09c467a-b65f-4636-bb80-67ba02bff5da@d10g2000yqh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have a function running a loop where a value is added to a vector at&lt;br&gt;
&amp;gt; each iteration. So, for example, if the vector is x, it could look&lt;br&gt;
&amp;gt; like:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Iteration 1: x=[1]&lt;br&gt;
&amp;gt; Iteration 2: x=[1,3]&lt;br&gt;
&amp;gt; Iteration 3: x=[1,3,2]&lt;br&gt;
&amp;gt; Iteration 4: x=[1,3,2,6]&lt;br&gt;
&amp;gt; Iteration 5: x=[1,3,2,6,2]&lt;br&gt;
&amp;gt; Iteration 6: x=[1,3,2,6,2,6]&lt;br&gt;
&amp;gt; Iteration 7: x=[1,3,2,6,2,6,2]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; and so on.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; As can be seen in the example above, at some point a repeating pattern&lt;br&gt;
&amp;gt; of values may appear in x; this indicates the function has entered an&lt;br&gt;
&amp;gt; infinite loop. I would like to be able to catch the pattern, say for&lt;br&gt;
&amp;gt; example after 3 repeats. In the example above, that would be when the&lt;br&gt;
&amp;gt; last 6 values of x are [2,6,2,6,2,6]; however, I do not know the&lt;br&gt;
&amp;gt; values in advance, nor do I know the length of the repeating pattern&lt;br&gt;
&amp;gt; (e.g. it could be [2,4,6,3,2,4,6,3,2,4,6,3]), though for practical&lt;br&gt;
&amp;gt; purposes three values should be sufficient to catch this error.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Can anyone suggest a way to identify this repeating pattern?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thx&lt;br&gt;
&lt;br&gt;
Why not compare the last N elements with the second-last N (if that is the right term for it?) elements? Something like&lt;br&gt;
&lt;br&gt;
if isequal(X(end-N+1:end),X(end-N-N+1:end-N))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;error('we are repeating ourselves ...') ;&lt;br&gt;
end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
hth&lt;br&gt;
Jos</description>
    </item>
    <item>
      <pubDate>Tue, 03 Nov 2009 16:25:03 -0500</pubDate>
      <title>Re: Identifying repeating pattern in a vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264837#691751</link>
      <author>Matt </author>
      <description>Eyal &amp;lt;efleminge@gmail.com&amp;gt; wrote in message &amp;lt;e09c467a-b65f-4636-bb80-67ba02bff5da@d10g2000yqh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have a function running a loop where a value is added to a vector at&lt;br&gt;
&amp;gt; each iteration. So, for example, if the vector is x, it could look&lt;br&gt;
&amp;gt; like:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Iteration 1: x=[1]&lt;br&gt;
&amp;gt; Iteration 2: x=[1,3]&lt;br&gt;
&amp;gt; Iteration 3: x=[1,3,2]&lt;br&gt;
&amp;gt; Iteration 4: x=[1,3,2,6]&lt;br&gt;
&amp;gt; Iteration 5: x=[1,3,2,6,2]&lt;br&gt;
&amp;gt; Iteration 6: x=[1,3,2,6,2,6]&lt;br&gt;
&amp;gt; Iteration 7: x=[1,3,2,6,2,6,2]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; and so on.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; As can be seen in the example above, at some point a repeating pattern&lt;br&gt;
&amp;gt; of values may appear in x; this indicates the function has entered an&lt;br&gt;
&amp;gt; infinite loop. I would like to be able to catch the pattern, say for&lt;br&gt;
&amp;gt; example after 3 repeats. In the example above, that would be when the&lt;br&gt;
&amp;gt; last 6 values of x are [2,6,2,6,2,6]; however, I do not know the&lt;br&gt;
&amp;gt; values in advance, nor do I know the length of the repeating pattern&lt;br&gt;
&amp;gt; (e.g. it could be [2,4,6,3,2,4,6,3,2,4,6,3]), though for practical&lt;br&gt;
&amp;gt; purposes three values should be sufficient to catch this error.&lt;br&gt;
&lt;br&gt;
It might be worthwhile explaining the process that generates x. It's obviously some kind of Markov process if 3 repititions is a certain indicator of an infinite loop. That means there might be a simpler state vector to monitor than the whole history of the process.</description>
    </item>
  </channel>
</rss>

