<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Finding Patterns in Arrays</title>
	<atom:link href="http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Thu, 09 Feb 2012 04:19:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Dave</title>
		<link>http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-32823</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Fri, 09 Dec 2011 02:19:27 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-32823</guid>
		<description>Hi Loren et al.,
As always, thanks for the great post! How about extending to the case where you don&#039;t know the exact pattern, but do know something about the pattern. For example, find the longest set of sequential numbers in a monotonically increasing array of integers. For example, in the sequence

a = [1 2 14 15 16 17 18 29 30 41 44 45],
,
the longest sequential set is 14:18. One vectorized way I came up with is:

b = find([1 ~(diff(a)==1) 1])
[~,c] = max(diff(b))
a(b(c):b(c+1)-1)

But I&#039;d love to hear of more elegant solutions. Thanks!</description>
		<content:encoded><![CDATA[<p>Hi Loren et al.,<br />
As always, thanks for the great post! How about extending to the case where you don&#8217;t know the exact pattern, but do know something about the pattern. For example, find the longest set of sequential numbers in a monotonically increasing array of integers. For example, in the sequence</p>
<p>a = [1 2 14 15 16 17 18 29 30 41 44 45],<br />
,<br />
the longest sequential set is 14:18. One vectorized way I came up with is:</p>
<p>b = find([1 ~(diff(a)==1) 1])<br />
[~,c] = max(diff(b))<br />
a(b(c):b(c+1)-1)</p>
<p>But I&#8217;d love to hear of more elegant solutions. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Malcolm Lidierth</title>
		<link>http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-32670</link>
		<dc:creator>Malcolm Lidierth</dc:creator>
		<pubDate>Wed, 16 Nov 2011 12:48:31 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-32670</guid>
		<description>@MN
If the original data  are only 2 or 3 bytes long, which I think is the case with MIDI, could you not typecast a to get 2 values per element then use find:
You may need to pad the end of a with zeros to align the data, then e.g
&lt;pre&gt;
a = [0 1 4 9 16 4 9 0 7 8 4 9 4 9 7 8 9 4 9 10];
a=uint32(a);
b=typecast(a,&#039;uint64&#039;);
% find odd numbered elements...
idxodd=(find(b==typecast(uint32([4,9]),&#039;uint64&#039;))-1)*2+1;
%then even
b=typecast([uint32(0) a uint32(0)], &#039;uint64&#039;);
idxeven=(find(b==typecast(uint32([4,9]),&#039;uint64&#039;))-1)*2;
% Both
idx=sort([idxodd idxeven])
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>@MN<br />
If the original data  are only 2 or 3 bytes long, which I think is the case with MIDI, could you not typecast a to get 2 values per element then use find:<br />
You may need to pad the end of a with zeros to align the data, then e.g</p>
<pre>
a = [0 1 4 9 16 4 9 0 7 8 4 9 4 9 7 8 9 4 9 10];
a=uint32(a);
b=typecast(a,'uint64');
% find odd numbered elements...
idxodd=(find(b==typecast(uint32([4,9]),'uint64'))-1)*2+1;
%then even
b=typecast([uint32(0) a uint32(0)], 'uint64');
idxeven=(find(b==typecast(uint32([4,9]),'uint64'))-1)*2;
% Both
idx=sort([idxodd idxeven])
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-32662</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 15 Nov 2011 21:25:40 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-32662</guid>
		<description>MN-

I can&#039;t think of an elegant way to do that.  Is it only 2 character matches you are looking for?  

Just thinking.  Here are 2 possible approaches.
1) You might create a new matrix with one row offset by one location (left or right, and padded to get all elements to be comparable) from the other row.  Transposing those into a nx2 array, you could then look for matched rows by calling intersect with the rows option perhaps.  But I haven&#039;t thought hard about this.
2)Something similar where you use diff to check...

--Loren</description>
		<content:encoded><![CDATA[<p>MN-</p>
<p>I can&#8217;t think of an elegant way to do that.  Is it only 2 character matches you are looking for?  </p>
<p>Just thinking.  Here are 2 possible approaches.<br />
1) You might create a new matrix with one row offset by one location (left or right, and padded to get all elements to be comparable) from the other row.  Transposing those into a nx2 array, you could then look for matched rows by calling intersect with the rows option perhaps.  But I haven&#8217;t thought hard about this.<br />
2)Something similar where you use diff to check&#8230;</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MN</title>
		<link>http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-32660</link>
		<dc:creator>MN</dc:creator>
		<pubDate>Tue, 15 Nov 2011 21:19:32 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-32660</guid>
		<description>Can you also find patterns without specifying the input?
If a = [0 1 4 9 16 4 9];
suppose I just wanted to find any pattern in which two adjacent characters repeat. The answer here would be: Pattern 4 9 and placement 3 6.
How would you do that?
I&#039;m actually working on a music analysis problem looking for melodic patterns in midi data.

Thanks,
MN</description>
		<content:encoded><![CDATA[<p>Can you also find patterns without specifying the input?<br />
If a = [0 1 4 9 16 4 9];<br />
suppose I just wanted to find any pattern in which two adjacent characters repeat. The answer here would be: Pattern 4 9 and placement 3 6.<br />
How would you do that?<br />
I&#8217;m actually working on a music analysis problem looking for melodic patterns in midi data.</p>
<p>Thanks,<br />
MN</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-31622</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Sun, 29 Aug 2010 15:42:37 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-31622</guid>
		<description>Stuart-

You have to define the criterion for choosing which one fits best - then compare the new data to each row in the dateset you already have.

--Loren</description>
		<content:encoded><![CDATA[<p>Stuart-</p>
<p>You have to define the criterion for choosing which one fits best &#8211; then compare the new data to each row in the dateset you already have.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Garner</title>
		<link>http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-31621</link>
		<dc:creator>Stuart Garner</dc:creator>
		<pubDate>Sat, 28 Aug 2010 21:27:32 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-31621</guid>
		<description>Suppose I had a data matrix with 8 rows and 800 columns, representing the results of 800 experiments with 8 variables each - call the 8 variables age, height, weight, etc.  Now suppose someone hands me a new column containing 8 data, in the same order as those in the matrix.  How do I find which of the other 800 columns best &quot;matches&quot; the new column?</description>
		<content:encoded><![CDATA[<p>Suppose I had a data matrix with 8 rows and 800 columns, representing the results of 800 experiments with 8 variables each &#8211; call the 8 variables age, height, weight, etc.  Now suppose someone hands me a new column containing 8 data, in the same order as those in the matrix.  How do I find which of the other 800 columns best &#8220;matches&#8221; the new column?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phil</title>
		<link>http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-31580</link>
		<dc:creator>Phil</dc:creator>
		<pubDate>Thu, 12 Aug 2010 16:47:23 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-31580</guid>
		<description>I found this really helpful, thanks. Is there a fast and easy way for searching patterns that extent over multiple rows and colums?

such as pattern=[0 1;0 0] in

[0 1 1 1; 0 0 1 1; 0 0 0 1; 0 0 0 0]. The search should fined three locations for such a pattern.

Any ideas?
Phil</description>
		<content:encoded><![CDATA[<p>I found this really helpful, thanks. Is there a fast and easy way for searching patterns that extent over multiple rows and colums?</p>
<p>such as pattern=[0 1;0 0] in</p>
<p>[0 1 1 1; 0 0 1 1; 0 0 0 1; 0 0 0 0]. The search should fined three locations for such a pattern.</p>
<p>Any ideas?<br />
Phil</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-30605</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 14 Sep 2009 11:27:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-30605</guid>
		<description>Rameez-

That&#039;s not the sort of pattern I was testing here initially.  What I would do with your situation is something like this.  Convert the array to logicals, where true represents data in the correct range.  Then look for a long-enough string on true values.  Get that index.  Voila.

--Loren</description>
		<content:encoded><![CDATA[<p>Rameez-</p>
<p>That&#8217;s not the sort of pattern I was testing here initially.  What I would do with your situation is something like this.  Convert the array to logicals, where true represents data in the correct range.  Then look for a long-enough string on true values.  Get that index.  Voila.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rameez Khan</title>
		<link>http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-30604</link>
		<dc:creator>Rameez Khan</dc:creator>
		<pubDate>Mon, 14 Sep 2009 11:22:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-30604</guid>
		<description>Hello,

Nice blog, and it proved quite useful to me as a student. 

I have a query, that if I am not sure of the exact no. of values that may occur for a range based pattern, then how will it may be done.

for. e.g.

I need to check for a pattern whose values may be between -3.7 to +3.7 and the no. of values in between them too aren&#039;t fixed as well. 

I have data from accelerometer against time. Which reads at 100Hz. So, I have alot data of the form for e.g:

time = [0.0000 0.0001 0.0002 0.0003 0.0004 0.0005 0.0006 0.0007 0.0008 0.0009.. ]
and
acc  = [ 2.345 3.345 6.454 6.545 -3.5 1.5 2.6 6 2.5 99 32 -3.7 1.3 -2 2.7 ... ]

Now I want to check for a pattern of values which stays between -3.7 to + 3.7 for a duration  0.05 seconds or greater not less that 0.05 seconds. I want of find the start and end time of the pattern.

thanks and kind regards,

/Rameez.</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>Nice blog, and it proved quite useful to me as a student. </p>
<p>I have a query, that if I am not sure of the exact no. of values that may occur for a range based pattern, then how will it may be done.</p>
<p>for. e.g.</p>
<p>I need to check for a pattern whose values may be between -3.7 to +3.7 and the no. of values in between them too aren&#8217;t fixed as well. </p>
<p>I have data from accelerometer against time. Which reads at 100Hz. So, I have alot data of the form for e.g:</p>
<p>time = [0.0000 0.0001 0.0002 0.0003 0.0004 0.0005 0.0006 0.0007 0.0008 0.0009.. ]<br />
and<br />
acc  = [ 2.345 3.345 6.454 6.545 -3.5 1.5 2.6 6 2.5 99 32 -3.7 1.3 -2 2.7 ... ]</p>
<p>Now I want to check for a pattern of values which stays between -3.7 to + 3.7 for a duration  0.05 seconds or greater not less that 0.05 seconds. I want of find the start and end time of the pattern.</p>
<p>thanks and kind regards,</p>
<p>/Rameez.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Krishna</title>
		<link>http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-30464</link>
		<dc:creator>Krishna</dc:creator>
		<pubDate>Sat, 11 Jul 2009 10:19:13 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/09/08/finding-patterns-in-arrays/#comment-30464</guid>
		<description>TRY strmatch.

Test how fast it can be</description>
		<content:encoded><![CDATA[<p>TRY strmatch.</p>
<p>Test how fast it can be</p>
]]></content:encoded>
	</item>
</channel>
</rss>

