If statement in Simulink is not like in a programming language, it accumulates last true value untill it occurs again.
As it can be seen here, when random value is lower than 0.5 (if condition) output dosn't give zero as one normally expects from if statement.
What is the proper way to use an if? (Where preferably I don't want to put saturation and matlab function)
The Out
block within the If Action
subsystem has a property to either hold
or reset
its output when disabled. The default is to hold; you want it to reset. You'll also need to specify 0
as the initial condition, which is what it'll reset to.