Reputation: 35
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)
Upvotes: 0
Views: 1753
Reputation: 21
Change out blocks property in If action subsystem to 'reset', it looks like it is 'held' in your current implementation
Upvotes: 1
Reputation: 10772
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.
Upvotes: 2
Reputation: 35
So far what I could do this to use an elementary matlab function;
function y = fcn(u)
if u>0
y = u;
else
y = 0;
end
end
but I wondered it would be a proper way of using if block.
Upvotes: 1