<?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: A Better If-Else Construct</title>
	<atom:link href="http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/</link>
	<description>This blog is about Simulink.</description>
	<lastBuildDate>Mon, 13 Feb 2012 09:45:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Guy Rouleau</title>
		<link>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-1476</link>
		<dc:creator>Guy Rouleau</dc:creator>
		<pubDate>Mon, 16 May 2011 12:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-1476</guid>
		<description>@rima, The Pulse Generator block takes different time steps when used with a variable step solver, versus fixed-step solver. This is why to see a different ouptut.

To avoid this change of behavior, I recommend following the guidelines provided in the Merge block documentation. Especially:

- Always use conditionally-executed subsystems to drive Merge blocks.

- Write your control logic to ensure that at most one of the driving conditionally-executed subsystems executes at any time step.</description>
		<content:encoded><![CDATA[<p>@rima, The Pulse Generator block takes different time steps when used with a variable step solver, versus fixed-step solver. This is why to see a different ouptut.</p>
<p>To avoid this change of behavior, I recommend following the guidelines provided in the Merge block documentation. Especially:</p>
<p>- Always use conditionally-executed subsystems to drive Merge blocks.</p>
<p>- Write your control logic to ensure that at most one of the driving conditionally-executed subsystems executes at any time step.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rima</title>
		<link>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-1475</link>
		<dc:creator>rima</dc:creator>
		<pubDate>Mon, 16 May 2011 11:14:08 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-1475</guid>
		<description>i am having problem using the merge block for a fixed step solver with sample time 0.1s. the problem is simple consisting of two pulse generator blocks and their o/p s are merged. the first pulse generator o/p a positive pulse of 0.5s pulse width &amp; 0.1 amp after 10 s.  the second pulse o/p a pulse of same pulse width but amp of -0.1 after 15s pulse delay. if i use a variable solver (ode45) the o/p of the merge block comes perfectly with consisting of a positive pulse followed by a negative pulse after 5 s. but if the solver is changed to fixed step solver (ode4 ) the o/p of the merge block is the negative pulse after 15s. the positive pulse disappears. i have change the pulse generator i/p to sample type with 0.1 s sample period then also the problem is not getting solved.</description>
		<content:encoded><![CDATA[<p>i am having problem using the merge block for a fixed step solver with sample time 0.1s. the problem is simple consisting of two pulse generator blocks and their o/p s are merged. the first pulse generator o/p a positive pulse of 0.5s pulse width &amp; 0.1 amp after 10 s.  the second pulse o/p a pulse of same pulse width but amp of -0.1 after 15s pulse delay. if i use a variable solver (ode45) the o/p of the merge block comes perfectly with consisting of a positive pulse followed by a negative pulse after 5 s. but if the solver is changed to fixed step solver (ode4 ) the o/p of the merge block is the negative pulse after 15s. the positive pulse disappears. i have change the pulse generator i/p to sample type with 0.1 s sample period then also the problem is not getting solved.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rima</title>
		<link>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-1474</link>
		<dc:creator>rima</dc:creator>
		<pubDate>Mon, 16 May 2011 11:07:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-1474</guid>
		<description>hi</description>
		<content:encoded><![CDATA[<p>hi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gerry</title>
		<link>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-999</link>
		<dc:creator>Gerry</dc:creator>
		<pubDate>Thu, 11 Mar 2010 15:21:30 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-999</guid>
		<description>Guy, I wanted to thank you.  I followed your instructions and &quot;reset&quot; the &quot;output&quot; with a specified value and that did the trick.  I would have never thought to double-click the output field for more options.

Gerry</description>
		<content:encoded><![CDATA[<p>Guy, I wanted to thank you.  I followed your instructions and &#8220;reset&#8221; the &#8220;output&#8221; with a specified value and that did the trick.  I would have never thought to double-click the output field for more options.</p>
<p>Gerry</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guy</title>
		<link>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-998</link>
		<dc:creator>Guy</dc:creator>
		<pubDate>Wed, 10 Mar 2010 19:39:01 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-998</guid>
		<description>Hi Gerry - By double-clicking on the output port of the conditionnal subsystem, you can specify the &quot;Output When Disabled&quot; to be &quot;reset&quot; or &quot;held&quot;. If you set it to &quot;reset&quot;, the output will reset to the value specified in the &quot;Initial Output&quot; parameter when the condition is false. You can see an example of it in the demo model sldemo_ifsub.mdl.

Guy</description>
		<content:encoded><![CDATA[<p>Hi Gerry &#8211; By double-clicking on the output port of the conditionnal subsystem, you can specify the &#8220;Output When Disabled&#8221; to be &#8220;reset&#8221; or &#8220;held&#8221;. If you set it to &#8220;reset&#8221;, the output will reset to the value specified in the &#8220;Initial Output&#8221; parameter when the condition is false. You can see an example of it in the demo model sldemo_ifsub.mdl.</p>
<p>Guy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gerry</title>
		<link>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-997</link>
		<dc:creator>Gerry</dc:creator>
		<pubDate>Wed, 10 Mar 2010 18:58:53 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-997</guid>
		<description>Seth,

   I&#039;m having trouble with &quot;if/then&quot; subsystem you described above.  I left a posted a message on Mathworks blog, yesterday, but gotten no responses.  I believe my trouble is correct syntax.  I believe it comes down to how to reset the &quot;if/then&quot; subsystem to false after it has been enabled the first time.  Your thoughts will be very helpful.

Gerry</description>
		<content:encoded><![CDATA[<p>Seth,</p>
<p>   I&#8217;m having trouble with &#8220;if/then&#8221; subsystem you described above.  I left a posted a message on Mathworks blog, yesterday, but gotten no responses.  I believe my trouble is correct syntax.  I believe it comes down to how to reset the &#8220;if/then&#8221; subsystem to false after it has been enabled the first time.  Your thoughts will be very helpful.</p>
<p>Gerry</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bindu</title>
		<link>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-881</link>
		<dc:creator>Bindu</dc:creator>
		<pubDate>Fri, 30 Oct 2009 06:55:18 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-881</guid>
		<description>please tell me how can i get the sampling time used in simulation</description>
		<content:encoded><![CDATA[<p>please tell me how can i get the sampling time used in simulation</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Seth</title>
		<link>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-832</link>
		<dc:creator>Seth</dc:creator>
		<pubDate>Wed, 26 Aug 2009 04:33:06 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-832</guid>
		<description>@Bob - You got me thinking about this.  I see what you mean about the number of wires and the challenge of making sure they get connected correctly every time.  I hope I&#039;ll be able to propose some kind of solution in a future post.

@valio - Start by rewriting the ODEs in terms of first order derivatives.  This was discussed in a previous blog post about &lt;a href=&quot;http://blogs.mathworks.com/seth/2008/05/23/how-to-draw-odes-in-simulink/&quot; rel=&quot;nofollow&quot;&gt;How to draw ODEs in Simulink&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>@Bob &#8211; You got me thinking about this.  I see what you mean about the number of wires and the challenge of making sure they get connected correctly every time.  I hope I&#8217;ll be able to propose some kind of solution in a future post.</p>
<p>@valio &#8211; Start by rewriting the ODEs in terms of first order derivatives.  This was discussed in a previous blog post about <a href="http://blogs.mathworks.com/seth/2008/05/23/how-to-draw-odes-in-simulink/" rel="nofollow">How to draw ODEs in Simulink</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: valio</title>
		<link>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-831</link>
		<dc:creator>valio</dc:creator>
		<pubDate>Tue, 25 Aug 2009 17:48:35 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-831</guid>
		<description>Hello Seth!

Read all your good articles.

But can you please consider my question for your next article of just give me your kind shortly explanation.

Cant build simulink model for that ODE:

L1*x1&#039; + R1*x1 + M12*x2&#039; + 1/C1*int(x) = 0 
L2*x2&#039; + R2*x2 + M21*x1&#039; = 0 
where  int(x1) = Uc 

build model like this:

http://picspix.com/img87/5728/16333.jpg

but it was failed..  

It&#039;s classic quotation of LC circuit+mutal inductance bind


Thanks a lot, and 
sorry for out of topic post.


Regards,
     Valentino.</description>
		<content:encoded><![CDATA[<p>Hello Seth!</p>
<p>Read all your good articles.</p>
<p>But can you please consider my question for your next article of just give me your kind shortly explanation.</p>
<p>Cant build simulink model for that ODE:</p>
<p>L1*x1&#8242; + R1*x1 + M12*x2&#8242; + 1/C1*int(x) = 0<br />
L2*x2&#8242; + R2*x2 + M21*x1&#8242; = 0<br />
where  int(x1) = Uc </p>
<p>build model like this:</p>
<p><a href="http://picspix.com/img87/5728/16333.jpg" rel="nofollow">http://picspix.com/img87/5728/16333.jpg</a></p>
<p>but it was failed..  </p>
<p>It&#8217;s classic quotation of LC circuit+mutal inductance bind</p>
<p>Thanks a lot, and<br />
sorry for out of topic post.</p>
<p>Regards,<br />
     Valentino.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-828</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Thu, 20 Aug 2009 13:00:58 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comment-828</guid>
		<description>A topic that has caused great trouble over the years.  As you mention, Simulink doesn&#039;t always apply the conditional execution optimization (code that has states is a common reason here) and so it is generally required that developers use the If/Action or the Switch/Action (a great alternative to an If block with u1==0, u1==1, u1==2,...).

These always draw complaints about how many lines one needs to connect properly, how easy it is to make a mistake, and how hard it is to visually inspect.  Most of the Action subsystems are more complex, with multiple inputs and outputs feeding multiple merge blocks and lines crossing everywhere.

To deal with this, I&#039;ve seen:
- Put all the merge blocks in a merge subsystem to prevent lines crossing.  Inside the merge subsystem, ports 1 &amp; 3 feed the first merge block, ports 2 &amp; 4 feed the second, or similar.
- Change the foreground color on the Action subsystem so the lines are colored and easier to trace.
- Use a virtual bus to bring all the signals together and then break apart without lines crossing.
- Use local From/Goto blocks to avoid crossing signals.

Some people also use the From/Goto to avoid having the dashed action lines crossing other lines on their way to that top port.

And because this is so messy, just the mechanics of implementing If/Then/Else logic gets dedicated to its own subsystem so it can be inspected independently.  If the logic is complex, sometimes the If block gets its own subsystem (or Stateflow chart with Boolean outputs) too.

We encourage people to do something, but don&#039;t have a standard.  What do others do to create maintainable models as the Action subsystem I/O grows?</description>
		<content:encoded><![CDATA[<p>A topic that has caused great trouble over the years.  As you mention, Simulink doesn&#8217;t always apply the conditional execution optimization (code that has states is a common reason here) and so it is generally required that developers use the If/Action or the Switch/Action (a great alternative to an If block with u1==0, u1==1, u1==2,&#8230;).</p>
<p>These always draw complaints about how many lines one needs to connect properly, how easy it is to make a mistake, and how hard it is to visually inspect.  Most of the Action subsystems are more complex, with multiple inputs and outputs feeding multiple merge blocks and lines crossing everywhere.</p>
<p>To deal with this, I&#8217;ve seen:<br />
- Put all the merge blocks in a merge subsystem to prevent lines crossing.  Inside the merge subsystem, ports 1 &amp; 3 feed the first merge block, ports 2 &amp; 4 feed the second, or similar.<br />
- Change the foreground color on the Action subsystem so the lines are colored and easier to trace.<br />
- Use a virtual bus to bring all the signals together and then break apart without lines crossing.<br />
- Use local From/Goto blocks to avoid crossing signals.</p>
<p>Some people also use the From/Goto to avoid having the dashed action lines crossing other lines on their way to that top port.</p>
<p>And because this is so messy, just the mechanics of implementing If/Then/Else logic gets dedicated to its own subsystem so it can be inspected independently.  If the logic is complex, sometimes the If block gets its own subsystem (or Stateflow chart with Boolean outputs) too.</p>
<p>We encourage people to do something, but don&#8217;t have a standard.  What do others do to create maintainable models as the Action subsystem I/O grows?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

