发表于:2005-08-30 16:02:00
楼主
设定了一个很长的仿真时间,如何在满足一定条件时提前退出仿真,如Simulink中的S函数中的
function [sys,x0,str,ts]=mdlInitialize
...
x0=[pi/300;0.2];
str=[];
ts=[-1 0];
function sys=mdlUpdate(t,x,u)
sys(1)=x(1)+u*T
sys(2)=x(2)+f(x,u,T)
function sys=mdlOutput(t,x,u)
sys=x(2);
function f=f(x,u,T)
if x(1)<pi/4
f=f1;
elseif x(1)<=pi/2
f=f2;
end
如果要求x(1)大于等于pi/2时就退出仿真该如何做?系统会在x(1)>=pi/2时自动退出吗?
如果我设定的仿真时间小于1320秒,系统运行正常,如果仿真设定的时间超过1320秒的时候会出现如下错误提示:
Error in block 'Level_control/S-Function' while executing M-File S-function block 'plant', flag = 2 (update), at time 1320. MATLAB error message:
In an assignment A(I) = B, the number of elements in B and
I must be the same
是不是系统在1320秒时,x(1)刚好达到pi/2,以后f(x,u,T)无定义所以出错了啊?
诚请教各位前辈、高手给指点指点,或相互讨论讨论,