<?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/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/</link>
	<description>Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.</description>
	<pubDate>Mon, 23 Nov 2009 00:19:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Rick Stauf</title>
		<link>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-746</link>
		<dc:creator>Rick Stauf</dc:creator>
		<pubDate>Tue, 29 Jul 2008 00:42:43 +0000</pubDate>
		<guid>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-746</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/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-745</link>
		<dc:creator>Rick Stauf</dc:creator>
		<pubDate>Mon, 28 Jul 2008 23:07:45 +0000</pubDate>
		<guid>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-745</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/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-751</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Thu, 27 Mar 2008 13:32:02 +0000</pubDate>
		<guid>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-751</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/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-752</link>
		<dc:creator>Phillip Diedrick</dc:creator>
		<pubDate>Thu, 27 Mar 2008 11:08:01 +0000</pubDate>
		<guid>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-752</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/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-753</link>
		<dc:creator>Jon</dc:creator>
		<pubDate>Thu, 20 Mar 2008 23:57:19 +0000</pubDate>
		<guid>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-753</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/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-744</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Fri, 11 Jan 2008 16:40:49 +0000</pubDate>
		<guid>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-744</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>
	<item>
		<title>By: Phil</title>
		<link>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-743</link>
		<dc:creator>Phil</dc:creator>
		<pubDate>Fri, 11 Jan 2008 03:05:59 +0000</pubDate>
		<guid>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-743</guid>
		<description>Doug,
I often see programmers rely on the 'if elseif' chain in order to determine if a variable (n) falls into one of several ranges.  MATLAB help is not clear on how this is done using the switch statement, but it is possible by comparing the logical value true against each of the range evaluations...

n=80
switch logical(true)
    case n&#62;100, disp('high');
    case n&#62;50, disp('moderate');
    case n&#62;0, disp('low');
    otherwise disp('invalid');
end;

Again, this is a much more elegant solution than the 'if elseif' alternative.

Phil.</description>
		<content:encoded><![CDATA[<p>Doug,<br />
I often see programmers rely on the &#8216;if elseif&#8217; chain in order to determine if a variable (n) falls into one of several ranges.  MATLAB help is not clear on how this is done using the switch statement, but it is possible by comparing the logical value true against each of the range evaluations&#8230;</p>
<p>n=80<br />
switch logical(true)<br />
    case n&gt;100, disp(&#8217;high&#8217;);<br />
    case n&gt;50, disp(&#8217;moderate&#8217;);<br />
    case n&gt;0, disp(&#8217;low&#8217;);<br />
    otherwise disp(&#8217;invalid&#8217;);<br />
end;</p>
<p>Again, this is a much more elegant solution than the &#8216;if elseif&#8217; alternative.</p>
<p>Phil.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-742</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Wed, 09 Jan 2008 16:59:17 +0000</pubDate>
		<guid>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-742</guid>
		<description>Robert,

I tested, and it really depended on the number of iterations.  For reasonable numbers of iterations it did not seem to matter.  TIC TOC and the profiler can be a big help here.

When asked about these kinds of things, I often say "Just code it", run the profiler and see where the problems are.  There is no need to try and optimize one second off of this kind of statement when there is some calculation that take 300 seconds anyways.  Write your code clean and maintainable, then modify the slow bits as they appear.

Doug</description>
		<content:encoded><![CDATA[<p>Robert,</p>
<p>I tested, and it really depended on the number of iterations.  For reasonable numbers of iterations it did not seem to matter.  TIC TOC and the profiler can be a big help here.</p>
<p>When asked about these kinds of things, I often say &#8220;Just code it&#8221;, run the profiler and see where the problems are.  There is no need to try and optimize one second off of this kind of statement when there is some calculation that take 300 seconds anyways.  Write your code clean and maintainable, then modify the slow bits as they appear.</p>
<p>Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert McCormick</title>
		<link>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-741</link>
		<dc:creator>Robert McCormick</dc:creator>
		<pubDate>Mon, 07 Jan 2008 00:24:55 +0000</pubDate>
		<guid>http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-741</guid>
		<description>Ok thanks Doug for this, but which of if-else and switch-case is computationally more efficient??</description>
		<content:encoded><![CDATA[<p>Ok thanks Doug for this, but which of if-else and switch-case is computationally more efficient??</p>
]]></content:encoded>
	</item>
</channel>
</rss>
