<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Learning Lessons from a One-Liner</title>
	<link>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/</link>
	<description>Steve Eddins manages the Image &#38; Geospatial development team at &#60;a href="http://www.mathworks.com/"&#62;The MathWorks&#60;/a&#62; and coauthored &#60;a href="http://www.mathworks.com/support/books/book5291.html?category=-1&#38;language=-1"&#62;Digital Image Processing Using MATLAB&#60;/a&#62;. He writes here about image processing concepts, algorithm implementations, and MATLAB.&#60;br&#62;&#60;br&#62;&#60;img&#62;</description>
	<pubDate>Mon, 23 Nov 2009 00:24:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Jos</title>
		<link>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21796</link>
		<dc:creator>Jos</dc:creator>
		<pubDate>Thu, 28 May 2009 08:50:40 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21796</guid>
		<description>What about:

&lt;pre&gt;
max(X(any([1 X(1:end-1) ; X(2:end) 1]==0)))
&lt;/pre&gt;

Jos</description>
		<content:encoded><![CDATA[<p>What about:</p>
<pre>
max(X(any([1 X(1:end-1) ; X(2:end) 1]==0)))
</pre>
<p>Jos</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken Eaton</title>
		<link>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21785</link>
		<dc:creator>Ken Eaton</dc:creator>
		<pubDate>Wed, 27 May 2009 15:55:34 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21785</guid>
		<description>It never ceases to amaze me how engrossing a simple one-line challenge can be. It certainly highlights how ugly and confusing a one-line solution often gets when you try to account for every possible case. For example, in trying to extend Steve's original solution to handle the additional test (vector "b") that he added, as well as the additional test below:

&lt;pre&gt;
c = [1 2 -4 0 0];  % repeated 0's and negative surrounds
&lt;/pre&gt;

I ended up with the horrendous one-liner:

&lt;pre&gt;
max([c(imdilate(c == 0,[1 1 1]) &#38; c) c(imerode(c == 0,[1 1 1]))])
&lt;/pre&gt;

This works for all 3 cases (a, b, and c), but is largely incomprehensible. Kudos to Doug for coming up with a solution that already satisfied my additional case.</description>
		<content:encoded><![CDATA[<p>It never ceases to amaze me how engrossing a simple one-line challenge can be. It certainly highlights how ugly and confusing a one-line solution often gets when you try to account for every possible case. For example, in trying to extend Steve&#8217;s original solution to handle the additional test (vector &#8220;b&#8221;) that he added, as well as the additional test below:</p>
<pre>
c = [1 2 -4 0 0];  % repeated 0's and negative surrounds
</pre>
<p>I ended up with the horrendous one-liner:</p>
<pre>
max([c(imdilate(c == 0,[1 1 1]) &amp; c) c(imerode(c == 0,[1 1 1]))])
</pre>
<p>This works for all 3 cases (a, b, and c), but is largely incomprehensible. Kudos to Doug for coming up with a solution that already satisfied my additional case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21784</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Wed, 27 May 2009 15:33:06 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21784</guid>
		<description>Doug&#8212;I appreciate the sentiment and the code suggestion.</description>
		<content:encoded><![CDATA[<p>Doug&mdash;I appreciate the sentiment and the code suggestion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug Schwarz</title>
		<link>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21783</link>
		<dc:creator>Doug Schwarz</dc:creator>
		<pubDate>Wed, 27 May 2009 15:31:08 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21783</guid>
		<description>Steve,

Anyone who has ever been in a position to support code written by others will soon learn to hate one-liners and I applaud your efforts to discourage this practice.

However, in the spirit of the blog, here's an idiom that can be used to detect entries adjacent to a 0 and does not require the IPT:

&lt;pre&gt;
isnan(conv(1./a,[0 1 0],'same'))
&lt;/pre&gt;

It's then a simple matter to use this as a mask and then apply max:

&lt;pre&gt;
max(a(isnan(conv(1./a,[0 1 0],'same'))))
&lt;/pre&gt;

Doug</description>
		<content:encoded><![CDATA[<p>Steve,</p>
<p>Anyone who has ever been in a position to support code written by others will soon learn to hate one-liners and I applaud your efforts to discourage this practice.</p>
<p>However, in the spirit of the blog, here&#8217;s an idiom that can be used to detect entries adjacent to a 0 and does not require the IPT:</p>
<pre>
isnan(conv(1./a,[0 1 0],'same'))
</pre>
<p>It&#8217;s then a simple matter to use this as a mask and then apply max:</p>
<pre>
max(a(isnan(conv(1./a,[0 1 0],'same'))))
</pre>
<p>Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21782</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Wed, 27 May 2009 15:18:10 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21782</guid>
		<description>Ken&#8212;No worries ... I misunderstood the problem statement at first myself.</description>
		<content:encoded><![CDATA[<p>Ken&mdash;No worries &#8230; I misunderstood the problem statement at first myself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken Eaton</title>
		<link>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21781</link>
		<dc:creator>Ken Eaton</dc:creator>
		<pubDate>Wed, 27 May 2009 15:12:50 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21781</guid>
		<description>Oops! I misunderstood... for some reason I read it as "the largest value AFTER a 0", but the values before the 0 count too. My bad!</description>
		<content:encoded><![CDATA[<p>Oops! I misunderstood&#8230; for some reason I read it as &#8220;the largest value AFTER a 0&#8243;, but the values before the 0 count too. My bad!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken Eaton</title>
		<link>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21780</link>
		<dc:creator>Ken Eaton</dc:creator>
		<pubDate>Wed, 27 May 2009 15:09:05 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/#comment-21780</guid>
		<description>Not sure how much easier it is to understand than yours, but this is the first answer I came up with:

&lt;pre&gt;
&#62;&#62; a = [1 5 3 0 2 7 0 8 9 1 0];
&#62;&#62; max(a(find([diff(a) 0] &#38; (a==0))+1))

ans =

     8

&#62;&#62; b = [5 4 -1 0 -2 0 -5 8];
&#62;&#62; max(b(find([diff(b) 0] &#38; (b==0))+1))

ans =

    -2

&lt;/pre&gt;

However, I thought of another strange case. What should the output be for this?

&lt;pre&gt;
c = [1 2 -4 3 0 0];
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Not sure how much easier it is to understand than yours, but this is the first answer I came up with:</p>
<pre>
&gt;&gt; a = [1 5 3 0 2 7 0 8 9 1 0];
&gt;&gt; max(a(find([diff(a) 0] &amp; (a==0))+1))

ans =

     8

&gt;&gt; b = [5 4 -1 0 -2 0 -5 8];
&gt;&gt; max(b(find([diff(b) 0] &amp; (b==0))+1))

ans =

    -2
</pre>
<p>However, I thought of another strange case. What should the output be for this?</p>
<pre>
c = [1 2 -4 3 0 0];
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
