Comments on: The If-Else Construct in Models https://blogs.mathworks.com/simulink/2009/06/02/the-if-else-construct-in-models/?s_tid=feedtopost Guy Rouleau is an Application Engineer for MathWorks. He writes here about Simulink and other MathWorks tools used in Model-Based Design. Tue, 06 Oct 2015 13:19:15 +0000 hourly 1 https://wordpress.org/?v=6.2.2 By: Anand https://blogs.mathworks.com/simulink/2009/06/02/the-if-else-construct-in-models/#comment-143035 Tue, 06 Oct 2015 13:19:15 +0000 https://blogs.mathworks.com/seth/2009/06/02/the-if-else-construct-in-models/#comment-143035 I am trying to implement something like
#if(condition) {
….
}
#else
{
….
}
Please let me know how this can be implemented in simulink?

]]>
By: Tabassum https://blogs.mathworks.com/simulink/2009/06/02/the-if-else-construct-in-models/#comment-1843 Thu, 24 May 2012 17:32:38 +0000 https://blogs.mathworks.com/seth/2009/06/02/the-if-else-construct-in-models/#comment-1843 oh God i got, wt i wanted…implementing a multiplexer

]]>
By: Seth Popinchalk https://blogs.mathworks.com/simulink/2009/06/02/the-if-else-construct-in-models/#comment-1597 Thu, 03 Nov 2011 20:21:03 +0000 https://blogs.mathworks.com/seth/2009/06/02/the-if-else-construct-in-models/#comment-1597 @Orucn – the Unit Delay represents a state in the system. States upstream of an switch block should not be optimized as the state still needs to update, no matter what the value of the switch. If you want it to execute differently, it would be better to explicitly model the conditional behavior. There is an example of this in the post titled A Better If-Else Construct.

]]>
By: Orcun https://blogs.mathworks.com/simulink/2009/06/02/the-if-else-construct-in-models/#comment-1595 Tue, 01 Nov 2011 12:38:55 +0000 https://blogs.mathworks.com/seth/2009/06/02/the-if-else-construct-in-models/#comment-1595 What if there is a unit delay or so in an input branch. Will the optimization work correct? Or just do the optimization for the part of the branch which is after the unit delay?

]]>
By: Seth https://blogs.mathworks.com/simulink/2009/06/02/the-if-else-construct-in-models/#comment-846 Fri, 11 Sep 2009 14:55:05 +0000 https://blogs.mathworks.com/seth/2009/06/02/the-if-else-construct-in-models/#comment-846 @HansUS – Notice that both sides of the IF statement reference the same temporary variable, in this case named rtb_in2. I think you are suggesting that it would be more efficient to directly write to the out variable, and you are correct. The reason this model doesn’t do that is because I disabled the expression folding optimization. The model is so simple that with expression folding turned on, both codes were the same. Please see important note 1 above. Thanks for the comment.

]]>
By: HansUS https://blogs.mathworks.com/simulink/2009/06/02/the-if-else-construct-in-models/#comment-845 Fri, 11 Sep 2009 13:11:13 +0000 https://blogs.mathworks.com/seth/2009/06/02/the-if-else-construct-in-models/#comment-845 I wonder if the pseudo code on the right is correct.
Copy and paste mistake?

Without the Signal storage reuse option set,
the if-branch should use rtb_in1 instead of rtb_in2.

With activated Signal storage reuse option,
both if- and else-branch should directly write to the out variable.

]]>
By: Ramin https://blogs.mathworks.com/simulink/2009/06/02/the-if-else-construct-in-models/#comment-823 Wed, 12 Aug 2009 18:27:00 +0000 https://blogs.mathworks.com/seth/2009/06/02/the-if-else-construct-in-models/#comment-823 Can this be used to pass in a large structure, then after the first pass, not have the large structure as input?
Like a Data File which gets passed in once, and then not looked passed in after that?

Does this just impact the generated code, or does the Matlab/Simulink Internals fetch the data anyways before the assignments in the code? I’d like to have a selector “first_time_called” then not have the input get copied since it won’t change after the first call in generated code or simulink engine. (Note: values in the file are not known until run time so it can’t be hard coded)

]]>
By: Seth https://blogs.mathworks.com/simulink/2009/06/02/the-if-else-construct-in-models/#comment-811 Tue, 21 Jul 2009 17:22:46 +0000 https://blogs.mathworks.com/seth/2009/06/02/the-if-else-construct-in-models/#comment-811 @Anand Rangaramu – I hope you can turn on this optimization, but I think you should also strive to add explicit specifications of conditional behavior to your model. Stay tuned for a post on that.

]]>
By: Anand Rangaramu https://blogs.mathworks.com/simulink/2009/06/02/the-if-else-construct-in-models/#comment-773 Fri, 12 Jun 2009 16:56:02 +0000 https://blogs.mathworks.com/seth/2009/06/02/the-if-else-construct-in-models/#comment-773 This is great. We need to implement this in our code.

]]>