<?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: Learning Lessons from a One-Liner</title>
	<atom:link href="http://blogs.mathworks.com/steve/2009/05/27/learning-lessons-from-a-one-liner/feed/" rel="self" type="application/rss+xml" />
	<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 The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.</description>
	<lastBuildDate>Sat, 11 Feb 2012 18:27:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.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 isPermaLink="false">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 isPermaLink="false">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&#039;s original solution to handle the additional test (vector &quot;b&quot;) that he added, as well as the additional test below:

&lt;pre&gt;
c = [1 2 -4 0 0];  % repeated 0&#039;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]) &amp; 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 isPermaLink="false">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 isPermaLink="false">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&#039;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],&#039;same&#039;))
&lt;/pre&gt;

It&#039;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],&#039;same&#039;))))
&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 isPermaLink="false">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 isPermaLink="false">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 &quot;the largest value AFTER a 0&quot;, 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 isPermaLink="false">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;
&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

&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>

