求助大神Simulink的一个小问题

求助

Simulink仿真中,一直提醒错误“Error in ‘lian2/S-Function’ while executing MATLAB S-function ‘pingjunzhi’, flag = 2 (update), at time 0.0.”
我的源程序是
function [sys,x0,str,ts] = pingjunzhi(t,x,u,flag)

switch flag
case 0
[sys,x0,str,ts]=mdlInitializeSizes;
case 2
sys=mdlUpdate(x,u);
case 3
sys=mdlOutputs(x);
case {1,4,9}
sys=[];
otherwise
error([‘Unhandled flag = ‘,num2str(flag)]);
end
end

function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;

sizes.NumContStates= 0;
sizes.NumDiscStates= 10;
sizes.NumOutputs= 1;
sizes.NumInputs= 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;

sys = simsizes(sizes);
x0= zeros(1,10);

str = [];
ts= [0.1 0];
end
function sys=mdlUpdate(x,u)
for i=9:-1:1
x(1,i+1)=x(1,i);
end
x(1,1)=u(1);
sys=x;

end
function sys=mdlOutputs(x)
sys=sum(x(1))/10;%计算平均值
end
哪位大神教教小白,万分感谢,头痛了几天了。

你可能感兴趣的:(求助大神Simulink的一个小问题)