simulink - How can i save previous value of variable in Matlab Function -
hello know how save previous value of output variable in matlab function.
function y = fcn(x,d,yp) yp=0; %here want initialize value @ start of simulation if (x-yp<=d) y=x; else y=yp + d; end yp=y; % here want load output value
thanks help
using persistent variable correct way go, found out, cannot use varargin
in matlab function block. trick check whether variable empty or not, in:
function y = fcn(x,d,yp) persistent yp if isempty(yp) yp=0; %only if yp empty, i.e. @ beginning of simulation end if (x-yp<=d) y=x; else y=yp + d; end yp=y; % here want load output value
Comments
Post a Comment