I'd like to include a function similar to the following in my codegen-compiled simulink model:
function u = PD_control( x )
x_last_iter = x;
Kp = 1; Kd = 1;
u = -x*Kp + (x_last_iter - x)*Kd
However, I get compiler error below. "IR Construction failed" returns zero hits when I search the web.
I can avoid this error by setting the initial value to 0 instead: "x_last_iter = 0;" But this is not ideal.