I need help using embedded matlab functions for an iterative learning controller
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Kaustubha Govind
le 19 Mar 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 commentaires
Voir également
Catégories
En savoir plus sur Deep Learning with GPU Coder dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!