<?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: Why is Answer to 3 &lt; A &lt; 7 Unexpected?</title>
	<atom:link href="http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/</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>Wed, 08 May 2013 12:21:15 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Paul</title>
		<link>http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/#comment-33062</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Sun, 27 May 2012 09:36:12 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=441#comment-33062</guid>
		<description>Really well written problem analysis</description>
		<content:encoded><![CDATA[<p>Really well written problem analysis</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/#comment-33061</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Thu, 24 May 2012 20:22:47 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=441#comment-33061</guid>
		<description>Chris-

That would be a poor choice.

&lt;pre class=&quot;code&quot;&gt;
A = 1:4;
sum(A&gt;3)
&lt;/pre

is a very convenient way to find out how many elements in A are greater than 3.  MATLAB has allowed reasonable calculations with logicals for a long time.  Taking that out now as a general rule would lead, I think, to incompatibilities that are likely not warranted.

--Loren</description>
		<content:encoded><![CDATA[<p>Chris-</p>
<p>That would be a poor choice.</p>
<pre class="code">
A = 1:4;<br />
sum(A>3)
</pre>
<p>is a very convenient way to find out how many elements in A are greater than 3.  MATLAB has allowed reasonable calculations with logicals for a long time.  Taking that out now as a general rule would lead, I think, to incompatibilities that are likely not warranted.</p>
<p>--Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/#comment-33060</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Thu, 24 May 2012 13:07:43 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=441#comment-33060</guid>
		<description>Better yet, warn on any arithmetic operation on a boolean (or &quot;logical&quot; as MATLAB appears to call that type).</description>
		<content:encoded><![CDATA[<p>Better yet, warn on any arithmetic operation on a boolean (or &#8220;logical&#8221; as MATLAB appears to call that type).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/#comment-33059</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Fri, 18 May 2012 08:03:00 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=441#comment-33059</guid>
		<description>Daniel-

I agree about the code analyzer message.  We already have that in our enhancement database.

--Loren</description>
		<content:encoded><![CDATA[<p>Daniel-</p>
<p>I agree about the code analyzer message.  We already have that in our enhancement database.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/#comment-33058</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Thu, 17 May 2012 12:46:40 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=441#comment-33058</guid>
		<description>While low &lt; x &lt; high is valid syntax, I cannot think of a use case where it is desirable. While I do not advocate changing the MATLAB language to accommodate, an mlint warning seems appropriate if there is never a desirable use for the syntax. The same holds for Matt&#039;s example.</description>
		<content:encoded><![CDATA[<p>While low &lt; x &lt; high is valid syntax, I cannot think of a use case where it is desirable. While I do not advocate changing the MATLAB language to accommodate, an mlint warning seems appropriate if there is never a desirable use for the syntax. The same holds for Matt&#039;s example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/#comment-33057</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Wed, 16 May 2012 21:16:13 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=441#comment-33057</guid>
		<description>Yes, Matt.  You mention items that I planned to write one or more blogs on in the future.

--Loren</description>
		<content:encoded><![CDATA[<p>Yes, Matt.  You mention items that I planned to write one or more blogs on in the future.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: matt fig</title>
		<link>http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/#comment-33056</link>
		<dc:creator>matt fig</dc:creator>
		<pubDate>Wed, 16 May 2012 19:07:49 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=441#comment-33056</guid>
		<description>Loren,

This type of mistake is about as common as two other, related mistaken uses of MATLAB&#039;s logical operators.  The first is when the user doesn&#039;t realize that MATLAB does not use the conditional to filter elements for operation inside the IF statement.  For example, I have often seen users do this:



x = 1:5;

if x&lt;=3
   x = 10;
end



The user expects this result:  x = [10 10 10 4 5]

The reason why the user expects this value is the false understanding that only those elements of x that satisfy the conditional statement are operated on inside the IF statement!  
As I mentioned before, this is related to the other common mistake.  The MATLAB IF conditional only passes through if all of the elements of a non-empty array evaluate to true.  Thus the previous example is equivalent to:



x = 1:5;

if all(x&lt;=3)
   x = 10;
end



Also note that the statement inside the IF statement reassigns x to a scalar value of 10; it never operates on any subset of elements.  Add to these the way MATLAB treats empty arrays and there is enough material for a long blog post (I know you have covered at least some of these topics before).</description>
		<content:encoded><![CDATA[<p>Loren,</p>
<p>This type of mistake is about as common as two other, related mistaken uses of MATLAB&#8217;s logical operators.  The first is when the user doesn&#8217;t realize that MATLAB does not use the conditional to filter elements for operation inside the IF statement.  For example, I have often seen users do this:</p>
<p>x = 1:5;</p>
<p>if x&lt;=3<br />
   x = 10;<br />
end</p>
<p>The user expects this result:  x = [10 10 10 4 5]</p>
<p>The reason why the user expects this value is the false understanding that only those elements of x that satisfy the conditional statement are operated on inside the IF statement!<br />
As I mentioned before, this is related to the other common mistake.  The MATLAB IF conditional only passes through if all of the elements of a non-empty array evaluate to true.  Thus the previous example is equivalent to:</p>
<p>x = 1:5;</p>
<p>if all(x&lt;=3)<br />
   x = 10;<br />
end</p>
<p>Also note that the statement inside the IF statement reassigns x to a scalar value of 10; it never operates on any subset of elements.  Add to these the way MATLAB treats empty arrays and there is enough material for a long blog post (I know you have covered at least some of these topics before).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/#comment-33055</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Tue, 15 May 2012 05:38:52 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=441#comment-33055</guid>
		<description>Espdev-

That&#039;s how the MATLAB language was designed, without x&lt;y&lt;z as an operator.  It&#039;s a consequence of the precedence of operators and left-to-right evaluation in MATLAB instead.

--Loren</description>
		<content:encoded><![CDATA[<p>Espdev-</p>
<p>That&#8217;s how the MATLAB language was designed, without x<y <z as an operator.  It's a consequence of the precedence of operators and left-to-right evaluation in MATLAB instead.</p>
<p>&#8211;Loren</p>
</y></p>]]></content:encoded>
	</item>
	<item>
		<title>By: Espdev</title>
		<link>http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/#comment-33054</link>
		<dc:creator>Espdev</dc:creator>
		<pubDate>Mon, 14 May 2012 11:41:56 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=441#comment-33054</guid>
		<description>Python is supported this expression. Why not do it in matlab?</description>
		<content:encoded><![CDATA[<p>Python is supported this expression. Why not do it in matlab?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
