<?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: MATLAB Basics: &#8216;Switch case&#8217; vs. &#8216;If elseif&#8217;</title>
	<atom:link href="http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/</link>
	<description>&#60;a href=&#34;http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1093599&#38;objectType=author&#34;&#62;Brett&#60;/a&#62; &#38; &#60;a href=&#34;http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1094142&#38;objectType=author&#34;&#62;Jiro&#60;/a&#62; share favorite user-contributed submissions from the File Exchange.</description>
	<lastBuildDate>Fri, 10 Feb 2012 16:12:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: vob player</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14342</link>
		<dc:creator>vob player</dc:creator>
		<pubDate>Tue, 29 Nov 2011 07:41:40 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14342</guid>
		<description>Cool script over there. Bet I can make use of it in some of my projects. Thank you so much.</description>
		<content:encoded><![CDATA[<p>Cool script over there. Bet I can make use of it in some of my projects. Thank you so much.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rushikesh Borse</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14326</link>
		<dc:creator>Rushikesh Borse</dc:creator>
		<pubDate>Sun, 20 Nov 2011 13:38:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14326</guid>
		<description>can we go for two conditions in switch case, i mean to say, val1, and val2, with an and operation. ot can we easily don usinf if, ifelse, if elseif else. but it is very expensive... can this we done using switch-case statements..

thanks for the very nice  video...

Rushikesh Borse</description>
		<content:encoded><![CDATA[<p>can we go for two conditions in switch case, i mean to say, val1, and val2, with an and operation. ot can we easily don usinf if, ifelse, if elseif else. but it is very expensive&#8230; can this we done using switch-case statements..</p>
<p>thanks for the very nice  video&#8230;</p>
<p>Rushikesh Borse</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: YouTube to mp4 converter</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14290</link>
		<dc:creator>YouTube to mp4 converter</dc:creator>
		<pubDate>Tue, 01 Nov 2011 11:32:23 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14290</guid>
		<description>Thanks so much, it&#039;s really essential info to me.</description>
		<content:encoded><![CDATA[<p>Thanks so much, it&#8217;s really essential info to me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: avi video player</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14278</link>
		<dc:creator>avi video player</dc:creator>
		<pubDate>Wed, 19 Oct 2011 08:50:19 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14278</guid>
		<description>Hi there!
Just wanted to thank you for such an amazing post you shared! It was so useful and helpful for me!</description>
		<content:encoded><![CDATA[<p>Hi there!<br />
Just wanted to thank you for such an amazing post you shared! It was so useful and helpful for me!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pdf editor freeware</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14266</link>
		<dc:creator>pdf editor freeware</dc:creator>
		<pubDate>Wed, 12 Oct 2011 10:02:08 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14266</guid>
		<description>Hey everyone!
It was so interesting to read this article, I found out a lot of interesting things!</description>
		<content:encoded><![CDATA[<p>Hey everyone!<br />
It was so interesting to read this article, I found out a lot of interesting things!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve L</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14231</link>
		<dc:creator>Steve L</dc:creator>
		<pubDate>Fri, 09 Sep 2011 13:39:40 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14231</guid>
		<description>Kwashie,

The way you&#039;ve written your code, the value alpha only depends on whether or not the last element of d is less than 1.5. Anyway, using &quot;logical indexing&quot; (you can search the documentation for this term for more information if you&#039;re interested) you can operate on a subset of the elements all at once.

&lt;pre&gt;
d = 1:0.1:2;
% Create a &quot;logical mask&quot;
smallEnough = d &lt; 1.5;
% Raise all elements of d to the 3rd power
k = d.^3;
% Square those elements that are &quot;small enough&quot; using the mask
k(smallEnough) = d(smallEnough).^2;
&lt;/pre&gt;
If you want alpha to be a vector the same size as d you can do what I did above (predefine it to be a vector of the same size as d with a &quot;default&quot; value then fill in certain elements to override that default) or you can do something slightly different:
&lt;pre&gt;
alpha = zeros(size(d));
alpha(smallEnough) = 2;
alpha(~smallEnough) = 4;
&lt;/pre&gt;
Note that I negated the smallEnough mask to set elements of alpha corresponding to those elements of d that were NOT smallEnough to 4. You can also AND (&amp;) or OR (&#124;) those logical masks together to form more complicated masks for use with logical indexing.</description>
		<content:encoded><![CDATA[<p>Kwashie,</p>
<p>The way you&#8217;ve written your code, the value alpha only depends on whether or not the last element of d is less than 1.5. Anyway, using &#8220;logical indexing&#8221; (you can search the documentation for this term for more information if you&#8217;re interested) you can operate on a subset of the elements all at once.</p>
<pre>
d = 1:0.1:2;
% Create a "logical mask"
smallEnough = d &lt; 1.5;
% Raise all elements of d to the 3rd power
k = d.^3;
% Square those elements that are "small enough" using the mask
k(smallEnough) = d(smallEnough).^2;
</pre>
<p>If you want alpha to be a vector the same size as d you can do what I did above (predefine it to be a vector of the same size as d with a &#8220;default&#8221; value then fill in certain elements to override that default) or you can do something slightly different:</p>
<pre>
alpha = zeros(size(d));
alpha(smallEnough) = 2;
alpha(~smallEnough) = 4;
</pre>
<p>Note that I negated the smallEnough mask to set elements of alpha corresponding to those elements of d that were NOT smallEnough to 4. You can also AND (&amp;) or OR (|) those logical masks together to form more complicated masks for use with logical indexing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kwashie</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14229</link>
		<dc:creator>Kwashie</dc:creator>
		<pubDate>Thu, 08 Sep 2011 10:57:55 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-14229</guid>
		<description>I have a vector and i want each element of the vector to be raised to a power depending on weather the element is greater or less than a fixed number. I tired using if statement but it is not working. Please can you help the fo
llowing is how i wrote the code:
&lt;pre&gt;
d = 1:0.1:2
for h = 1:length(d)
if d(h)(1,:)&amp;it 1.500
alpha = 2
else
alpha = 4
end
k(h)(1,:) = d(h)(1,:)^2
end
&lt;/pre&gt;
Thank you, your help will be much appreciated.</description>
		<content:encoded><![CDATA[<p>I have a vector and i want each element of the vector to be raised to a power depending on weather the element is greater or less than a fixed number. I tired using if statement but it is not working. Please can you help the fo<br />
llowing is how i wrote the code:</p>
<pre>
d = 1:0.1:2
for h = 1:length(d)
if d(h)(1,:)&amp;it 1.500
alpha = 2
else
alpha = 4
end
k(h)(1,:) = d(h)(1,:)^2
end
</pre>
<p>Thank you, your help will be much appreciated.</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-13936</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Wed, 17 Nov 2010 16:02:47 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13936</guid>
		<description>@Ricardo,

Your code simplified looks like this:

&lt;pre class=&quot;code&quot;&gt;

While 1
   do something
end

&lt;/pre&gt;

The boolean in the while statement is ALWAYS true, that is why you never leave the loop.

Doug</description>
		<content:encoded><![CDATA[<p>@Ricardo,</p>
<p>Your code simplified looks like this:</p>
<pre class="code">

While 1
   do something
end
</pre>
<p>The boolean in the while statement is ALWAYS true, that is why you never leave the loop.</p>
<p>Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricardo</title>
		<link>http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13935</link>
		<dc:creator>Ricardo</dc:creator>
		<pubDate>Wed, 17 Nov 2010 15:28:26 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13935</guid>
		<description>Doug, thank you for this example, i&#039;m starting to learn matlab and i want to use the switch in my program but i have my switch inside a while that is itself inside a for something like this:

n=2;
for i=1:n,
 disp(&#039;types of things&#039;)
    disp(&#039;1 - thing one&#039;)
    disp(&#039;2 - thing two&#039;)
    disp(&#039;3 - thing 3&#039;)
    disp(&#039;4 - thing 4&#039;)
    opcomb=input(strcat (&#039;what&#039;s the number &#039;,num2str(i),&#039;thing:&#039;,32));
    while ((opcomb ~=1)&#124;(opcomb~=2)&#124;(opcomb~=3)&#124;&#124;(opcomb~=4))
        switch opcomb
            case 1 
                combst(i)= 1; 
            case 2
                combst(i)=2; 
            case 3
                combst(i)=3;     
            case 4
                combst(i)=4;    
            otherwise
                disp(&#039;wrong answer&#039;)
                opcomb=input(strcat (&#039;what&#039;s the number &#039;,num2str(i),&#039;thing:&#039;,32));                
        end
    end
end

what its doing is after choosing in the first opcomb and then entering the switch it doesnt &quot;come out&quot;...i&#039;m at a loss as to where my problem is, if it&#039;s in the switch or in the conditions i set in whyle.
thank you in advance</description>
		<content:encoded><![CDATA[<p>Doug, thank you for this example, i&#8217;m starting to learn matlab and i want to use the switch in my program but i have my switch inside a while that is itself inside a for something like this:</p>
<p>n=2;<br />
for i=1:n,<br />
 disp(&#8216;types of things&#8217;)<br />
    disp(&#8217;1 &#8211; thing one&#8217;)<br />
    disp(&#8217;2 &#8211; thing two&#8217;)<br />
    disp(&#8217;3 &#8211; thing 3&#8242;)<br />
    disp(&#8217;4 &#8211; thing 4&#8242;)<br />
    opcomb=input(strcat (&#8216;what&#8217;s the number &#8216;,num2str(i),&#8217;thing:&#8217;,32));<br />
    while ((opcomb ~=1)|(opcomb~=2)|(opcomb~=3)||(opcomb~=4))<br />
        switch opcomb<br />
            case 1<br />
                combst(i)= 1;<br />
            case 2<br />
                combst(i)=2;<br />
            case 3<br />
                combst(i)=3;<br />
            case 4<br />
                combst(i)=4;<br />
            otherwise<br />
                disp(&#8216;wrong answer&#8217;)<br />
                opcomb=input(strcat (&#8216;what&#8217;s the number &#8216;,num2str(i),&#8217;thing:&#8217;,32));<br />
        end<br />
    end<br />
end</p>
<p>what its doing is after choosing in the first opcomb and then entering the switch it doesnt &#8220;come out&#8221;&#8230;i&#8217;m at a loss as to where my problem is, if it&#8217;s in the switch or in the conditions i set in whyle.<br />
thank you in advance</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-13713</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Thu, 22 Jul 2010 13:44:20 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/#comment-13713</guid>
		<description>@Nicole,

I don&#039;t know, but one quick test is worth a thousand expert opinions! :)

I would first get the code working and then profile to find the bottle necks.   They are rarely where you expect them.

Doug</description>
		<content:encoded><![CDATA[<p>@Nicole,</p>
<p>I don&#8217;t know, but one quick test is worth a thousand expert opinions! :)</p>
<p>I would first get the code working and then profile to find the bottle necks.   They are rarely where you expect them.</p>
<p>Doug</p>
]]></content:encoded>
	</item>
</channel>
</rss>

