<?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: Bottom Line on Logical</title>
	<atom:link href="http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/</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: Martin</title>
		<link>http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/#comment-31906</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Thu, 09 Dec 2010 10:58:56 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=64#comment-31906</guid>
		<description>Hi Loren &amp; Jiro,

ISMEMBER is definitely easier to handle when the serach is based on specified values, but I seems the element-wise OR can implement flexible clauses using relational operators:

&lt;pre&gt;
R = K( (K == 7) &#124; (K &lt; 20) )


&lt;/pre&gt;


Best,
Martin</description>
		<content:encoded><![CDATA[<p>Hi Loren &amp; Jiro,</p>
<p>ISMEMBER is definitely easier to handle when the serach is based on specified values, but I seems the element-wise OR can implement flexible clauses using relational operators:</p>
<pre>
R = K( (K == 7) | (K &lt; 20) )
</pre>
<p>Best,<br />
Martin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jiro</title>
		<link>http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/#comment-31894</link>
		<dc:creator>jiro</dc:creator>
		<pubDate>Fri, 03 Dec 2010 20:05:23 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=64#comment-31894</guid>
		<description>@Martin,

Also note that even using the element-wise OR requires you to find the indices first (it&#039;s doing that internally), just like you can do this with ISMEMBER:

&lt;pre&gt;
R = K(ismember(K,[7 18]))
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>@Martin,</p>
<p>Also note that even using the element-wise OR requires you to find the indices first (it&#8217;s doing that internally), just like you can do this with ISMEMBER:</p>
<pre>
R = K(ismember(K,[7 18]))
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/#comment-31893</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Fri, 03 Dec 2010 16:38:14 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=64#comment-31893</guid>
		<description>Martin-

The reason I recommend ismember is that is scales up for however many values you want to check.  Using the elementwise OR requires an indeterminate number of clauses (Jiro shows N=2 above).

--Loren</description>
		<content:encoded><![CDATA[<p>Martin-</p>
<p>The reason I recommend ismember is that is scales up for however many values you want to check.  Using the elementwise OR requires an indeterminate number of clauses (Jiro shows N=2 above).</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/#comment-31892</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Fri, 03 Dec 2010 16:04:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=64#comment-31892</guid>
		<description>Hi Loren &amp; Jiro,

I find the element-wise OR a good solution in this case. ismember would require first finding the indices and then indexing

&lt;pre&gt;
ind = ismember(key,[7 18])
R = K(ind)
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hi Loren &amp; Jiro,</p>
<p>I find the element-wise OR a good solution in this case. ismember would require first finding the indices and then indexing</p>
<pre>
ind = ismember(key,[7 18])
R = K(ind)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: jiro</title>
		<link>http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/#comment-31883</link>
		<dc:creator>jiro</dc:creator>
		<pubDate>Mon, 29 Nov 2010 12:52:52 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=64#comment-31883</guid>
		<description>@Martin,

I agree with Loren about using ISMEMBER for matching more than one. If you want to make it work with logical operators, you would do this:

&lt;pre&gt;
R = K( (K == 7) &#124; (K == 18) )

&lt;/pre&gt;


&quot;Find where K is either 7 or 18&quot;. Note that you don&#039;t use the short-circuit OR</description>
		<content:encoded><![CDATA[<p>@Martin,</p>
<p>I agree with Loren about using ISMEMBER for matching more than one. If you want to make it work with logical operators, you would do this:</p>
<pre>
R = K( (K == 7) | (K == 18) )
</pre>
<p>&#8220;Find where K is either 7 or 18&#8243;. Note that you don&#8217;t use the short-circuit OR</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/#comment-31881</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 29 Nov 2010 12:15:28 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=64#comment-31881</guid>
		<description>Martin-

Look into ismember for matching more than 1 value.

--Loren</description>
		<content:encoded><![CDATA[<p>Martin-</p>
<p>Look into ismember for matching more than 1 value.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/#comment-31879</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Fri, 26 Nov 2010 12:25:57 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=64#comment-31879</guid>
		<description>Hi Loren,

I am having trouble indexing with == for more than one case match. Let array K be

&lt;pre&gt;
K =

    20
     7
    18
    20
    20
    20

&lt;/pre&gt;

which I want to reduce to only contain values &#039;7&#039; and &#039;18&#039;. I could use 

&lt;pre&gt;
R = K(K &lt; 20)

&lt;/pre&gt;

 or

&lt;pre&gt;

R = K(K ~= 20)

&lt;/pre&gt;

but want I really want is to index with == for both values &#039;7&#039; and &#039;18&#039;. I works for one value

&lt;pre&gt;
R = K(K == 7)

&lt;/pre&gt;

but I cannot make to work for more values using &amp;&amp;

Best,
Martin</description>
		<content:encoded><![CDATA[<p>Hi Loren,</p>
<p>I am having trouble indexing with == for more than one case match. Let array K be</p>
<pre>
K =

    20
     7
    18
    20
    20
    20
</pre>
<p>which I want to reduce to only contain values &#8217;7&#8242; and &#8217;18&#8242;. I could use </p>
<pre>
R = K(K &lt; 20)
</pre>
<p> or</p>
<pre>

R = K(K ~= 20)
</pre>
<p>but want I really want is to index with == for both values &#8217;7&#8242; and &#8217;18&#8242;. I works for one value</p>
<pre>
R = K(K == 7)
</pre>
<p>but I cannot make to work for more values using &amp;&amp;</p>
<p>Best,<br />
Martin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver A. Chapman, PE</title>
		<link>http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/#comment-14265</link>
		<dc:creator>Oliver A. Chapman, PE</dc:creator>
		<pubDate>Mon, 06 Nov 2006 17:42:41 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=64#comment-14265</guid>
		<description>Steve &amp; Loren,

Certainly it is fair for you to defend the way MatLab operates.  And, you are correct regarding the documentation of the &quot;if&quot; statement.

Even though I continue to lobby MatLab for specific improvements in the documentation when I encounter deficiencies, the documentation for &quot;if&quot; is very good.

However, for well designed software, the documentation serves as a backstop to its logical &amp; reasonable operation.  Further, in this case, the documentation of the &quot;or&quot; operator doesn&#039;t give any hint to its different behavior when imbedded in an &quot;if&quot; statement.

I stand by the point I made that none of us here think it is reasonable for the outcome for an &quot;or&quot; operation be order dependent.

Further, I am more troubled by Steve&#039;s comments regarding the specification for the &quot;or&quot; statement.  A reasonable answer would be something like, &quot;Yes MatLab&#039;s specification for the &quot;or&quot; statement does discuss this behavior, but for proprietary reasons, we can&#039;t share it with you.&quot;  Instead, he glosses over the issue with a &quot;non-denial-denial.&quot;

In my first reply to this, on November 1, I assumed there was a performance benefit to this feature and asked for an example.  No reply yet.  Show us how these other customers have taken advantage of this feature.

Reading between the lines, I suspect that this behavior kind of &quot;happened&quot; in the original version of MatLab and has recently been incorporated into the current specifications.

Here is the bottom line:  MatLab is an expensive bit of software that is well worth the price.  It is generally very well designed and has outstanding documentation.  Users can quickly engage with MatLab even when approaching it from varied backgrounds and perspectives.

However, for the users like me and those around me, this feature that we&#039;ve been discussing is not expected and Loren&#039;s column is a good forum to discuss it.  I read her column just so I can learn these details.  Give some examples as I discuss above and then we&#039;ll move on to other topics.</description>
		<content:encoded><![CDATA[<p>Steve &amp; Loren,</p>
<p>Certainly it is fair for you to defend the way MatLab operates.  And, you are correct regarding the documentation of the &#8220;if&#8221; statement.</p>
<p>Even though I continue to lobby MatLab for specific improvements in the documentation when I encounter deficiencies, the documentation for &#8220;if&#8221; is very good.</p>
<p>However, for well designed software, the documentation serves as a backstop to its logical &amp; reasonable operation.  Further, in this case, the documentation of the &#8220;or&#8221; operator doesn&#8217;t give any hint to its different behavior when imbedded in an &#8220;if&#8221; statement.</p>
<p>I stand by the point I made that none of us here think it is reasonable for the outcome for an &#8220;or&#8221; operation be order dependent.</p>
<p>Further, I am more troubled by Steve&#8217;s comments regarding the specification for the &#8220;or&#8221; statement.  A reasonable answer would be something like, &#8220;Yes MatLab&#8217;s specification for the &#8220;or&#8221; statement does discuss this behavior, but for proprietary reasons, we can&#8217;t share it with you.&#8221;  Instead, he glosses over the issue with a &#8220;non-denial-denial.&#8221;</p>
<p>In my first reply to this, on November 1, I assumed there was a performance benefit to this feature and asked for an example.  No reply yet.  Show us how these other customers have taken advantage of this feature.</p>
<p>Reading between the lines, I suspect that this behavior kind of &#8220;happened&#8221; in the original version of MatLab and has recently been incorporated into the current specifications.</p>
<p>Here is the bottom line:  MatLab is an expensive bit of software that is well worth the price.  It is generally very well designed and has outstanding documentation.  Users can quickly engage with MatLab even when approaching it from varied backgrounds and perspectives.</p>
<p>However, for the users like me and those around me, this feature that we&#8217;ve been discussing is not expected and Loren&#8217;s column is a good forum to discuss it.  I read her column just so I can learn these details.  Give some examples as I discuss above and then we&#8217;ll move on to other topics.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Eddins</title>
		<link>http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/#comment-14177</link>
		<dc:creator>Steve Eddins</dc:creator>
		<pubDate>Sat, 04 Nov 2006 02:06:35 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=64#comment-14177</guid>
		<description>Oliver - I understand your consternation about this behavior.  Believe me, you are not alone.  But there&#039;s no reason for your suggestion of a lack of a spec.  In fact, the behavior is completely documented. (See Documentation -&gt; MATLAB -&gt; MATLAB Programming -&gt; Logical Operators -&gt; Short-Circuiting in Element-Wise Operators.)

We cannot change this behavior now without breaking a great deal of existing customer code.  So what we have done instead is to introduce the scalar, always-short-circuiting logical operators, and to encourage their use in if and while conditionals.  The MATLAB Editor will even make this suggestion to you if you use &quot;&#124;&quot; or &quot;&amp;&quot; in an if or while conditional expression.</description>
		<content:encoded><![CDATA[<p>Oliver &#8211; I understand your consternation about this behavior.  Believe me, you are not alone.  But there&#8217;s no reason for your suggestion of a lack of a spec.  In fact, the behavior is completely documented. (See Documentation -&gt; MATLAB -&gt; MATLAB Programming -&gt; Logical Operators -&gt; Short-Circuiting in Element-Wise Operators.)</p>
<p>We cannot change this behavior now without breaking a great deal of existing customer code.  So what we have done instead is to introduce the scalar, always-short-circuiting logical operators, and to encourage their use in if and while conditionals.  The MATLAB Editor will even make this suggestion to you if you use &#8220;|&#8221; or &#8220;&amp;&#8221; in an if or while conditional expression.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver A. Chapman, PE</title>
		<link>http://blogs.mathworks.com/loren/2006/11/02/bottom-line-on-logical/#comment-14176</link>
		<dc:creator>Oliver A. Chapman, PE</dc:creator>
		<pubDate>Sat, 04 Nov 2006 01:06:06 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=64#comment-14176</guid>
		<description>Loren,

I think that MatLab has made this sufficiently complex.

Let&#039;s go back to the &quot;or&quot; operator.

&gt;&gt; []&#124;4

ans =

     []

&gt;&gt; 4&#124;[]

ans =

     []

As expected, I get the empty result, regardless of order of the inputs.

But, there is no rational justification for the different result if imbedded in an if or while statement.

&gt;&gt; if []&#124;4
disp(&#039;true&#039;);
else
disp(&#039;false&#039;);
end;
false


&gt;&gt; if 4&#124;[]
disp(&#039;true&#039;);
else
disp(&#039;false&#039;);
end;
true
&gt;&gt;

What does the specification for the MatLab &quot;if&quot; statement say regarding this feature?

Or, was the &quot;if&quot; statement written without a specification?</description>
		<content:encoded><![CDATA[<p>Loren,</p>
<p>I think that MatLab has made this sufficiently complex.</p>
<p>Let&#8217;s go back to the &#8220;or&#8221; operator.</p>
<p>&gt;&gt; []|4</p>
<p>ans =</p>
<p>     []</p>
<p>&gt;&gt; 4|[]</p>
<p>ans =</p>
<p>     []</p>
<p>As expected, I get the empty result, regardless of order of the inputs.</p>
<p>But, there is no rational justification for the different result if imbedded in an if or while statement.</p>
<p>&gt;&gt; if []|4<br />
disp(&#8216;true&#8217;);<br />
else<br />
disp(&#8216;false&#8217;);<br />
end;<br />
false</p>
<p>&gt;&gt; if 4|[]<br />
disp(&#8216;true&#8217;);<br />
else<br />
disp(&#8216;false&#8217;);<br />
end;<br />
true<br />
&gt;&gt;</p>
<p>What does the specification for the MatLab &#8220;if&#8221; statement say regarding this feature?</p>
<p>Or, was the &#8220;if&#8221; statement written without a specification?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

