I need help using embedded matlab functions for an iterative learning controller
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Kaustubha Govind
am 19 Mär. 2013
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 Kommentare
Siehe auch
Kategorien
Mehr zu Deep Learning with GPU Coder finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!