When i Run following program coding. I got these two errors : Error in water/execute (line 54) x1=kp4(@func, t, x1, u1, h); Error in water (line 4) execute;..Please anybody can help?

function water
clf;
initialize;
execute;
function initialize
subplot 221
global gh1 x1 r1
x1=0.2; r1=0.8;
hold on
plot([-0.5 -0.5 0.5 0.5],[1.2 0 0 1.2],'g','linewidth',3);
plot([0.5 1],[0 0],'g','linewidth',2);
plot([1.2 1 1.2 1 1.2],[0.15 0 0 0 -0.15],'b','linewidth',2);
plot([-1 0 0],[1.6 1.6 1.5],'g','linewidth',2);
plot([-0.1 0 0 0 0.1],[1.3 1.5 1.3 1.5 1.3],'b','linewidth',2);
gh1=fill([-0.5 -0.5 0.5 0.5],[x1 0 0 x1],'b');
title('General System');
hold off
subplot 222
global gh2 x2 r2
cla
x2=0.2; r2=0.8;
hold on
plot([-0.5 -0.5 0.5 0.5],[1.2 0 0 1.2],'g','linewidth',3);
plot([0.5 1],[0 0],'g','linewidth',2);
plot([1.2 1 1.2 1 1.2],[0.15 0 0 0 -0.15],'b','linewidth',2);
plot([-1 0 0],[1.6 1.6 1.5],'g','linewidth',2);
plot([-0.1 0 0 0 0.1],[1.3 1.5 1.3 1.5 1.3],'b','linewidth',2);
gh2=fill([-0.5 -0.5 0.5 0.5],[x2 0 0 x2],'b');
title('Controlled System');
hold off
end
function execute
global gh1 gh2 x1 r1 x2 r2;
check1=0.5; check2=0.5;
t=0; h=0.01; z=0;
kp=3; ki=1;
for i=0:200
u1=r1-x1;
if u1<0
u1=0;
end
e=r2-x2;
z=z+h+e;
if e>=0
u2=kp+e+ki+z;
else
u2=0;
end
x1=kp4(@func, t, x1, u1, h);
x2=kp4(@func, t, x2, u2, h);
t=t+h;
set(gh1, 'ydata' ,[x1 0 0 x1]);
set(gh2, 'ydata' ,[x2 0 0 x2]);
subplot 223
hold on
if check1<1
if x1>=0.78
fill([t-0.05 t t+0.05],[0.2 0 0.2],'r');
check1=1;
end
end
plot(t,x1);
axis 'equal'
axis([0 2 0 1.1]);
hold off
subplot 224
hold on
if check2<1
if x2>=0.78
fill([t-0.05 t t+0.05],[0.2 0 0.2],'r');
check2=1;
end
end
plot(t,x2);
axis 'equal'
axis([0 2 0 1.1]);
hold off
title('controlled System')
drawnow;
pause(0.1);
end
end
end
function xdot=func(t,x,u)
g=9.8; A=0.003; S=0.3;
xdot=(u-A+sqrt(2+g+x))/S;
end

3 个评论

kp4 is a function......you have to define it...it is missing int he code.
THAT'S all i have to do .. what about line 4 error .. execute
That was part of the traceback. The problem was detected inside the function named execute, and it showed you the line number of the problem, and it showed you the line in which execute was called.

回答(1 个)

There can be only one error: Matlab stops after the first (uncaught) error. The multiple lines you see in the error message are the "traceback" (as Walter has explained already): This is the "calling stack", the list of function calls to reach the failing line. It helps to identify, from where the code has been called.

此问题已关闭。

提问:

2017-11-6

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by