<?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: MATLAB Basics: &#8216;Switch case&#8217; vs. &#8216;If elseif&#8217;</title>
	<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/</link>
	<description>&#60;a href="http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=969735&#38;objectType=author"&#62;Bob&#60;/a&#62;, &#60;a href="http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1093599&#38;objectType=author"&#62;Brett&#60;/a&#62; &#38; &#60;a href="http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1094142&#38;objectType=author"&#62;Jiro&#60;/a&#62; share favorite user-contributed submissions from the File Exchange.</description>
	<pubDate>Mon, 23 Nov 2009 00:51:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13042</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 17 Feb 2009 16:09:00 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13042</guid>
		<description>Carly,

Switch/case can be used in functions or scripts.

The switch command can work on any variable, not just one put in by the user.

Doug</description>
		<content:encoded><![CDATA[<p>Carly,</p>
<p>Switch/case can be used in functions or scripts.</p>
<p>The switch command can work on any variable, not just one put in by the user.</p>
<p>Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carly</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13039</link>
		<dc:creator>Carly</dc:creator>
		<pubDate>Mon, 16 Feb 2009 02:00:24 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13039</guid>
		<description>Do the switch/case commands go in the function file or the script file.

Is there a way to automatically do the switch command or do you have to ask the user to input the value that you want to switch.</description>
		<content:encoded><![CDATA[<p>Do the switch/case commands go in the function file or the script file.</p>
<p>Is there a way to automatically do the switch command or do you have to ask the user to input the value that you want to switch.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13017</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Thu, 29 Jan 2009 20:52:20 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13017</guid>
		<description>I think instead of
if (x &lt; y &lt; z)

you want

if (x &lt; y) &#038; (y &lt; z)

The first construct could be done with numbers like this:

&gt;&gt; 0 &lt; 0.5 &lt; 1

ans =

     0

(I suspect you expected the statement to be true!)

Which has an implied parenthesis here:

(0 &lt; 0.5) &lt; 1

Since (0 &lt; 0.5) evaluates to true (1) this means
1 &lt; 1

Which evaluates to false (0)

Try my construct:

&gt;&gt; (0 &lt; 0.5) &#038; (0.5 &lt; 1)

ans =

     1

And I think you will get what you were expecting.

-Doug</description>
		<content:encoded><![CDATA[<p>I think instead of<br />
if (x < y < z)</p>
</p><p>you want</p>
<p>if (x < y) &#038; (y < z)</p>
</p><p>The first construct could be done with numbers like this:</p>
<p>>> 0 < 0.5 < 1</p>
</p><p>ans =</p>
<p>     0</p>
<p>(I suspect you expected the statement to be true!)</p>
<p>Which has an implied parenthesis here:</p>
<p>(0 < 0.5) < 1</p>
</p><p>Since (0 < 0.5) evaluates to true (1) this means<br />
1 < 1</p>
</p><p>Which evaluates to false (0)</p>
<p>Try my construct:</p>
<p>>> (0 < 0.5) &#038; (0.5 < 1)</p>
</p><p>ans =</p>
<p>     1</p>
<p>And I think you will get what you were expecting.</p>
<p>-Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yuri</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13015</link>
		<dc:creator>Yuri</dc:creator>
		<pubDate>Thu, 29 Jan 2009 11:40:13 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13015</guid>
		<description>I've got a question about this string. Before this is a whole m-script with the needed parameterinputs, and there is no problem with them. It's this particular part, where i need to get the 2000&#62;REwater&#62;3000 to work. But I believe this is not a right command for a Matlab m-file. Do you know an alternative to get REwater be unknown when the Reynoldsnumber is larger than 2000 but less than 3000?
Thanks in advance!


REwater=(roowater*v*D)/etawater                                                                                 
if REwater3000
    disp('The liquid is turbulent')
elseif 2000&#62;REwater&#60;3000
    disp('The liquid of water is unknown, laminair and turbulent')
end</description>
		<content:encoded><![CDATA[<p>I&#8217;ve got a question about this string. Before this is a whole m-script with the needed parameterinputs, and there is no problem with them. It&#8217;s this particular part, where i need to get the 2000&gt;REwater&gt;3000 to work. But I believe this is not a right command for a Matlab m-file. Do you know an alternative to get REwater be unknown when the Reynoldsnumber is larger than 2000 but less than 3000?<br />
Thanks in advance!</p>
<p>REwater=(roowater*v*D)/etawater<br />
if REwater3000<br />
    disp(&#8217;The liquid is turbulent&#8217;)<br />
elseif 2000&gt;REwater&lt;3000<br />
    disp(&#8217;The liquid of water is unknown, laminair and turbulent&#8217;)<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Stauf</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-12266</link>
		<dc:creator>Rick Stauf</dc:creator>
		<pubDate>Tue, 29 Jul 2008 00:42:43 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-12266</guid>
		<description>Never Mind, I found a more efficient way to do it. Instead of searching the time area I simply multiply the time by the delta time to acquire the index number in the array. Thanks for your web tutorials. They are very helpful.</description>
		<content:encoded><![CDATA[<p>Never Mind, I found a more efficient way to do it. Instead of searching the time area I simply multiply the time by the delta time to acquire the index number in the array. Thanks for your web tutorials. They are very helpful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Stauf</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-12265</link>
		<dc:creator>Rick Stauf</dc:creator>
		<pubDate>Mon, 28 Jul 2008 23:07:45 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-12265</guid>
		<description>Doug,

I'm looking for a GoTo function for Matlab. I have an efficient search routine that I like to use in a number of areas that requires GoTos. Is there anything like this in matlab procedures?

Thank you for your help,
Rick</description>
		<content:encoded><![CDATA[<p>Doug,</p>
<p>I&#8217;m looking for a GoTo function for Matlab. I have an efficient search routine that I like to use in a number of areas that requires GoTos. Is there anything like this in matlab procedures?</p>
<p>Thank you for your help,<br />
Rick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-10256</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Thu, 27 Mar 2008 13:32:02 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-10256</guid>
		<description>Phillip,

You need this for your input statement:

n=input('Please input the figure:','s')

This interprets whatever is typed as a string.  Without that switch, MATLAB is taking what you type and interpreting it and thus looks for a function called "triangle" or whatever and does not find it.

Doug</description>
		<content:encoded><![CDATA[<p>Phillip,</p>
<p>You need this for your input statement:</p>
<p>n=input(&#8217;Please input the figure:&#8217;,&#8217;s&#8217;)</p>
<p>This interprets whatever is typed as a string.  Without that switch, MATLAB is taking what you type and interpreting it and thus looks for a function called &#8220;triangle&#8221; or whatever and does not find it.</p>
<p>Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phillip Diedrick</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-10255</link>
		<dc:creator>Phillip Diedrick</dc:creator>
		<pubDate>Thu, 27 Mar 2008 11:08:01 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-10255</guid>
		<description>I want to use the switch/case for the following. I want to prompt the user to input one the following strings: triangle, square,pentagon or hexagon. Depending which figure you input the program will then calculate the sum of the interior angles of the figure using (n-2)(180). I tried the following and I'm prompted with an error message. Here is my code.
clear;
clc;
n=input('Please input the figure:')
switch n
case ('triangle')
n=3;
sum=(n-3).*(180)
case ('square')
n=4;
sum=(n-3).*(180)
case('pentagon')
n=5;
sum=(n-3).*(180)
case ('hexagon')
n=6;
sum=(n-3).*(180)
end
Please could you assist me.
Thanks</description>
		<content:encoded><![CDATA[<p>I want to use the switch/case for the following. I want to prompt the user to input one the following strings: triangle, square,pentagon or hexagon. Depending which figure you input the program will then calculate the sum of the interior angles of the figure using (n-2)(180). I tried the following and I&#8217;m prompted with an error message. Here is my code.<br />
clear;<br />
clc;<br />
n=input(&#8217;Please input the figure:&#8217;)<br />
switch n<br />
case (&#8217;triangle&#8217;)<br />
n=3;<br />
sum=(n-3).*(180)<br />
case (&#8217;square&#8217;)<br />
n=4;<br />
sum=(n-3).*(180)<br />
case(&#8217;pentagon&#8217;)<br />
n=5;<br />
sum=(n-3).*(180)<br />
case (&#8217;hexagon&#8217;)<br />
n=6;<br />
sum=(n-3).*(180)<br />
end<br />
Please could you assist me.<br />
Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-10110</link>
		<dc:creator>Jon</dc:creator>
		<pubDate>Thu, 20 Mar 2008 23:57:19 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-10110</guid>
		<description>Phil, 

 Thanks for that! Exactly what I was looking for.  MATLAB help does kind of fail to explain how to use logicals with a switch statement.

Jon</description>
		<content:encoded><![CDATA[<p>Phil, </p>
<p> Thanks for that! Exactly what I was looking for.  MATLAB help does kind of fail to explain how to use logicals with a switch statement.</p>
<p>Jon</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-8408</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Fri, 11 Jan 2008 16:40:49 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-8408</guid>
		<description>Phil,

Excellent example.  Thank you!

Doug</description>
		<content:encoded><![CDATA[<p>Phil,</p>
<p>Excellent example.  Thank you!</p>
<p>Doug</p>
]]></content:encoded>
	</item>
</channel>
</rss>
