<?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: Find Largest Positive Value Next to Zero</title>
	<link>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/</link>
	<description>Loren Shure  works on design of the MATLAB language at &#60;a href="http://www.mathworks.com/"&#62;The MathWorks&#60;/a&#62;. She writes here about once a week on MATLAB programming and related topics. &#60;br&#62;&#60;br&#62;&#60;a href="/images/loren-full.jpg"&#62;&#60;img src="/images/loren.jpg"&#62;&#60;/a&#62;</description>
	<pubDate>Sun, 22 Nov 2009 23:33:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: OysterEngineer</title>
		<link>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30709</link>
		<dc:creator>OysterEngineer</dc:creator>
		<pubDate>Tue, 27 Oct 2009 23:30:18 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30709</guid>
		<description>Loren,

Your solution is clear to follow.  i.e., the code demonstrates what it is doing.

The solutions that are shown from Steve, Doug &#38; Jos are not clear.  Certainly it can be fun to study them.  But, I would never use them in real code.

I really think that Djykstra was correct in saying that the code should demonstrate that it is correct.</description>
		<content:encoded><![CDATA[<p>Loren,</p>
<p>Your solution is clear to follow.  i.e., the code demonstrates what it is doing.</p>
<p>The solutions that are shown from Steve, Doug &amp; Jos are not clear.  Certainly it can be fun to study them.  But, I would never use them in real code.</p>
<p>I really think that Djykstra was correct in saying that the code should demonstrate that it is correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Akiel</title>
		<link>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30479</link>
		<dc:creator>Akiel</dc:creator>
		<pubDate>Sun, 19 Jul 2009 19:04:41 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30479</guid>
		<description>How about this:
max(A(logical(conv(~A+0, [1 0 1], 'same'))))
I haven't looked at any of the other solutions, so maybe someone's already done this.</description>
		<content:encoded><![CDATA[<p>How about this:<br />
max(A(logical(conv(~A+0, [1 0 1], &#8217;same&#8217;))))<br />
I haven&#8217;t looked at any of the other solutions, so maybe someone&#8217;s already done this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brett Shoelson</title>
		<link>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30476</link>
		<dc:creator>Brett Shoelson</dc:creator>
		<pubDate>Fri, 17 Jul 2009 19:24:36 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30476</guid>
		<description>Hi Loren,
Late to the game--have been on vacation--but wanted to throw my solution into the mix. Cheers!
Brett

First, pad B, then use &#124;BSXFUN&#124;:

&lt;pre&gt;
C = [-Inf B -Inf]; 
max(max(C(bsxfun(@plus,find(~C),[-1,1]'))))
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hi Loren,<br />
Late to the game&#8211;have been on vacation&#8211;but wanted to throw my solution into the mix. Cheers!<br />
Brett</p>
<p>First, pad B, then use |BSXFUN|:</p>
<pre>
C = [-Inf B -Inf];
max(max(C(bsxfun(@plus,find(~C),[-1,1]'))))
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thijs</title>
		<link>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30454</link>
		<dc:creator>Thijs</dc:creator>
		<pubDate>Mon, 06 Jul 2009 07:14:02 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30454</guid>
		<description>My option would be the following:
&lt;pre&gt;
max(A([false A(1:end-1)==0]&#124;[A(2:end)==0 false]))
&lt;/pre&gt;

or the identical, but slightly more compact:
&lt;pre&gt;
max(A([0 A(1:end-1)==0]&#124;[A(2:end)==0 0]))
&lt;/pre&gt;

pretty similar to what already has been posted though.</description>
		<content:encoded><![CDATA[<p>My option would be the following:</p>
<pre>
max(A([false A(1:end-1)==0]|[A(2:end)==0 false]))
</pre>
<p>or the identical, but slightly more compact:</p>
<pre>
max(A([0 A(1:end-1)==0]|[A(2:end)==0 0]))
</pre>
<p>pretty similar to what already has been posted though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30452</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Fri, 03 Jul 2009 12:04:04 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30452</guid>
		<description>Jos-

You're right about the title!

Ben- 

Thanks for another solution.

--Loren</description>
		<content:encoded><![CDATA[<p>Jos-</p>
<p>You&#8217;re right about the title!</p>
<p>Ben- </p>
<p>Thanks for another solution.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jos</title>
		<link>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30451</link>
		<dc:creator>Jos</dc:creator>
		<pubDate>Fri, 03 Jul 2009 09:31:17 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30451</guid>
		<description>Again an interesting blog! However, the title of this blog is somewhat misleading. Shouldn't the word "positive" be removed?

- jos</description>
		<content:encoded><![CDATA[<p>Again an interesting blog! However, the title of this blog is somewhat misleading. Shouldn&#8217;t the word &#8220;positive&#8221; be removed?</p>
<p>- jos</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30450</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Fri, 03 Jul 2009 07:48:45 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30450</guid>
		<description>I think Mike's answer is probably the most intuitive, but I would have answered it like Jos only using "&#124;" instead of "any".
&lt;pre&gt;
fb = @(X)max(X([1,X(1:end-1)]==0 &#124; [X(2:end),1]==0))
&lt;/pre&gt;

An even shorter code is
&lt;pre&gt;
fb2 = @(X)max(X([1,X(1:end-1)].*[X(2:end),1]==0))
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I think Mike&#8217;s answer is probably the most intuitive, but I would have answered it like Jos only using &#8220;|&#8221; instead of &#8220;any&#8221;.</p>
<pre>
fb = @(X)max(X([1,X(1:end-1)]==0 | [X(2:end),1]==0))
</pre>
<p>An even shorter code is</p>
<pre>
fb2 = @(X)max(X([1,X(1:end-1)].*[X(2:end),1]==0))
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pär Lansåker</title>
		<link>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30449</link>
		<dc:creator>Pär Lansåker</dc:creator>
		<pubDate>Thu, 02 Jul 2009 18:53:12 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30449</guid>
		<description>It is often better to use an obvious path for understanding. I would use a combinationd of diff(A) (find the largest, not forgetting the negative left hand side) and A==0 (adjecent to 0).</description>
		<content:encoded><![CDATA[<p>It is often better to use an obvious path for understanding. I would use a combinationd of diff(A) (find the largest, not forgetting the negative left hand side) and A==0 (adjecent to 0).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Koets</title>
		<link>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30447</link>
		<dc:creator>Mike Koets</dc:creator>
		<pubDate>Thu, 02 Jul 2009 16:23:41 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30447</guid>
		<description>If we &lt;i&gt;do&lt;/i&gt; want to allow answers of zero (I assumed we did not want that), then we can use this code &lt;pre&gt;max(c(intersect(1:length(c),[find(c==0)+1 find(c==0)-1])))&lt;/pre&gt;  Now the intersect just removes out of bounds results.</description>
		<content:encoded><![CDATA[<p>If we <i>do</i> want to allow answers of zero (I assumed we did not want that), then we can use this code
<pre>max(c(intersect(1:length(c),[find(c==0)+1 find(c==0)-1])))</pre>
</p><p>  Now the intersect just removes out of bounds results.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30446</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 02 Jul 2009 15:06:01 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2009/07/01/find-largest-positive-value-next-to-zero/#comment-30446</guid>
		<description>Matt-

Your solution is certainly viable as well!

--Loren</description>
		<content:encoded><![CDATA[<p>Matt-</p>
<p>Your solution is certainly viable as well!</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
</channel>
</rss>
