I need help using embedded matlab functions for an iterative learning controller
조회 수: 8 (최근 30일)
이전 댓글 표시
I am working with a learning controller for a motor for a periodic signal. I want to store the followerror on each time sample during the first period, in a vector. Then I want to output these values the next period, and also rewrite them with the new followerror.
currently I am using:
function y = fcn(u,t)
%#codegen
d=round(t);
z=zeros(1,99999);
y=z(1,d+1);
z(1,d+1)=u;
t is a time counter that resets every period
but this doesn't seem to work, it keeps showing zero... Can anyone help me?
댓글 수: 0
답변 (1개)
Kaustubha Govind
2013년 3월 19일
You are using the variable 'z' as a state, but note that the line:
z=zeros(1,99999);
is executed at every time-step, so 'z' is reset to all zeros every time. You might want to define 'z' as a persistent variable instead:
function y = fcn(u,t)
%#codegen
persistent z;
d=round(t);
if isempty(z)
z=zeros(1,99999);
end
y=z(1,d+1);
z(1,d+1)=u;
PS: You might also want to look into whether you are assigning 'z' correctly, you are using y=z(1,d+1), but z(1,d+1)=u; only on the next line. Did you mean to say y=z(1,d)?
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!