Set and reset Simulink

1 view (last 30 days)
Adam Keller
Adam Keller on 26 Jul 2015
Commented: Adam Keller on 26 Jul 2015
Hello,
I am having trouble regarding value holding and reset with a simulink function. When a condition occurs I would like to have that value held until an external reset occurs.
Ex)
if x==7
z = 6; % but z stays at 6 even after x does not equal 7
elseif reset ==1 %reset occurs
z = 0;
end
I would like to trigger a value, hold, use an external signal to reset, and then allow to trigger again. Is there a block that can do this?
Many thanks.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 26 Jul 2015
Edited: Azzi Abdelmalek on 26 Jul 2015
Try this
function z=fcn(x,reset)
persitent xx
if isempty(xx)
xx=0
end
if (x==7|xx==1) & reset==0
z = 6;
xx=1;
elseif reset==1
z = 0;
xx=0
end
  3 Comments
Adam Keller
Adam Keller on 26 Jul 2015
That's what I meant, my apologies. Thank you Azzi!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!