MATLAB: Is the IF statement in the component not evaluated correctly in SimScape 3.2 (R2009b)

Simscape

I am building a custom physical component using SimScape language. I have observed that for my custom component, the 'IF-ELSE' condition in the equations section is not evaluated correctly.
For example, for the code below, 'a' is never equal to 1 despite cond1 changes from false to true during the simulation.
if cond1
a=1;
else
a=0;
end

Best Answer

This enhancement has been incorporated in Release 2010b (R2010b). For previous product releases, read below for any possible workarounds:
This issue could be related to Zero-Crossing control not being enabled. When Zero-Crossing detection is disabled in the model, the condition of the “IF-ELSE” statement is only checked at the beginning of the simulation. The Simscape Engine requires an “event” to re-compute the “Transient Initialization” and if there is no external input, this event must be a Zero-Crossing generated by a discontinuous function (“<” in this case).
In Simulink when Zero-Crossing detection is disabled, a function like “<” will be evaluated the next time it is executed, but this is not the case in Simscape. This can lead to unexpected results.
For more information regarding Zero-Crossing detection, please consult the following documentation: