Simulink error: index eceeds array dimentions. Index value 0 eceeds validing (1-2) array u_past.

1 次查看(过去 30 天)
I'm trying to use Matlab Func to make sth. I tried this code as a .m file, then i tried to use it in simulink's matlab function. But This error is coming up. What is wrong with this code?. Plz some one help me.☺
This is my code. Matlab 2019b
if true
function [U, refrense] = fcn(Ym_now, g, G, p, m, W)
persistent u_past f landa step u ;
if isempty(u_past)||isempty(f)||isempty(landa)||isempty(step)||isempty(u)
f=zeros(p,1);
u_past=zeros(1,size(g,2)+1);
landa=1;
step=1;
u=0;
end
F=0;
K=(G'*G+landa*eye(m))\G';
for k=1:p
for i=1:k
F=( g(k+i)-g(i) ) * ( u_past(1,size(g,2)-i+1) - u_past(1,size(g,2)-i));
end
f(k,1)=F+Ym_now;
end
u_past(1,1:end-1)=u_past(1,2:end);
u=K(1,:)*(W(step:(p+step-1),1)-f)+u;
u_past(1,end)=u;
U=u;
refrense=W(step,1);
step=step+1;
end
end
  3 个评论
MR.Vaezi
MR.Vaezi 2020-3-3
Dear Roberson, This is the error message observed.
index eceeds array dimentions. Index value 0 eceeds validing (1-2) array u_past.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by