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

1 view (last 30 days)
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 Comments
MR.Vaezi
MR.Vaezi on 3 Mar 2020
Dear Roberson, This is the error message observed.
index eceeds array dimentions. Index value 0 eceeds validing (1-2) array u_past.
MR.Vaezi
MR.Vaezi on 3 Mar 2020
Edited: MR.Vaezi on 3 Mar 2020

For this line:

    F=( g(k+i)-g(i) ) * ( u_past(1,size(g,2)-i+1) - u_past(1,size(g,2)-i));

Sign in to comment.

Answers (0)

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!