各位大神,MATLAB新手一枚求指教!
我照着一本电机控制的教材,用S-Function的模板编写的函数,可是运行时一直提示输入参数不够,可是这个函数已经不需要其他的输入参数,实在不知道原因,希望大神可以指导一下!
函数如下:
function[sys,x0,str,ts]=eabc(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates= 0;
sizes.NumDiscStates= 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0= [];
str = [];
ts= [0 0];
function sys=mdlDerivatives(t,x,u)
%ea
if(u(1)<0)
f(1)=0;
end
if(u(1)>=0&&u(1)
f(1)=6*u(2)*u(1)/pi;
end
if(u(1)>=pi/6&&u(1)<5*pi/6)
f(1)=u(2);
end
if(u(1)>=5*pi/6&&u(1)<7*pi/6)
f(1)=-6*u(2)*u(1)/pi+6*u(2);
end
if(u(1)>=7*pi/6&&u(1)<11*pi/6)
f(1)=-u(2);
end
if(u(1)>=11*pi/6&&u(1)<2*pi)
f(1)=6*u(2)*u(1)/pi-12*u(2);
end
if(u(1)>=2*pi)
f(1)=0;
end
%eb
if(u(1)<0)
f(2)=0;
end
if(u(1)>=0&&u(1)
f(2)=-u(2);
end
if(u(1)>=pi/2&&u(1)<5*pi/6)
f(2)=6*u(2)*u(1)/pi-4*u(2);
end
if(u(1)>=5*pi/6&&u(1)<9*pi/6)
f(2)=u(2);
end
if(u(1)>=9*pi/6&&u(1)<11*pi/6)
f(2)=-6*u(2)*u(1)/pi+10*u(2);
end
if(u(1)>=11*pi/6&&u(1)<2*pi)
f(2)=-u(2);
end
if(u(1)>=2*pi)
f(2)=0;
end
%ec
if(u(1)<0)
f(3)=0;
end
if(u(1)>=0&&u(1)
f(3)=u(2);
end
if(u(1)>=pi/6&&u(1)
f(3)=-6*u(2)*u(1)/pi+2*u(2);
end
if(u(1)>=pi/2&&u(1)<7*pi/6)
f(3)=-u(2);
end
if(u(1)>=7*pi/6&&u(1)<9*pi/6)
f(3)=6*u(2)*u(1)/pi-8*u(2);
end
if(u(1)>=9*pi/6&&u(1)<2*pi)
f(3)=u(2);
end
if(u(1)>=2*pi)
f(3)=0;
end
sys = [f(1);f(2);f(3)];
function sys=mdlUpdate(t,x,u)
sys = [];
function sys=mdlOutputs(t,x,u)
%ea
if(u(1)<0)
f(1)=0;
end
if(u(1)>=0&&u(1)
f(1)=6*u(2)*u(1)/pi;
end
if(u(1)>=pi/6&&u(1)<5*pi/6)
f(1)=u(2);
end
if(u(1)>=5*pi/6&&u(1)<7*pi/6)
f(1)=-6*u(2)*u(1)/pi+6*u(2);
end
if(u(1)>=7*pi/6&&u(1)<11*pi/6)
f(1)=-u(2);
end
if(u(1)>=11*pi/6&&u(1)<2*pi)
f(1)=6*u(2)*u(1)/pi-12*u(2);
end
if(u(1)>=2*pi)
f(1)=0;
end
%eb
if(u(1)<0)
f(2)=0;
end
if(u(1)>=0&&u(1)
f(2)=-u(2);
end
if(u(1)>=pi/2&&u(1)<5*pi/6)
f(2)=6*u(2)*u(1)/pi-4*u(2);
end
if(u(1)>=5*pi/6&&u(1)<9*pi/6)
f(2)=u(2);
end
if(u(1)>=9*pi/6&&u(1)<11*pi/6)
f(2)=-6*u(2)*u(1)/pi+10*u(2);
end
if(u(1)>=11*pi/6&&u(1)<2*pi)
f(2)=-u(2);
end
if(u(1)>=2*pi)
f(2)=0;
end
%ec
if(u(1)<0)
f(3)=0;
end
if(u(1)>=0&&u(1)
f(3)=u(2);
end
if(u(1)>=pi/6&&u(1)
f(3)=-6*u(2)*u(1)/pi+2*u(2);
end
if(u(1)>=pi/2&&u(1)<7*pi/6)
f(3)=-u(2);
end
if(u(1)>=7*pi/6&&u(1)<9*pi/6)
f(3)=6*u(2)*u(1)/pi-8*u(2);
end
if(u(1)>=9*pi/6&&u(1)<2*pi)
f(3)=u(2);
end
if(u(1)>=2*pi)
f(3)=0;
end
sys = [f(1);f(2);f(3)];
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1;
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];