フィルターのクリア

I need help using embedded matlab functions for an iterative learning controller

2 ビュー (過去 30 日間)
Rune
Rune 2013 年 3 月 19 日
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?

回答 (1 件)

Kaustubha Govind
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)?

カテゴリ

Help Center および File ExchangeDeep Learning with GPU Coder についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by