用S函数写的一段根据转子位置求反电势的代码,但是老是报错,盼高手点评一下
本帖最后由 张子富 于 2011-11-20 10:53 编辑function = emf(t,x,u,flag)
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
case {1,2,4}
sys=[];
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function =mdlInitializeSizes(t,x,u)
sizes = simsizes;
sizes.NumContStates= 0;
sizes.NumDiscStates= 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0= [];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts= [-1 0];
%
function sys=mdlDerivatives(t,x,u)
sys = [];
% end mdlDerivatives
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u)
sys = [];
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
if(u>=0)&&(u<pi/3)
sys=;
elseif(u>=pi/3)&&(u<2*pi/3)
sys=;
elseif(u>=2*pi/3)&&(u<pi)
sys=[-u*6/pi+5 1 -1];
elseif(u>=pi)&&(u<4*pi/3)
sys=[-1 1 u*6/pi-7];
elseif(u>=4*pi/3)&&(u<5*pi/3)
sys=[-1 -u*6/pi+9 1];
elseif(u>=5*pi/3)&&(u<2*pi)
sys=;
end
% end mdlOutputs
%
%=============================================================================
% mdlGetTimeOfNextVarHit
% Return the time of the next hit for this block.Note that the result is
% absolute time.Note that this function is only used when you specify a
% variable discrete-time sample time [-2 0] in the sample time array in
% mdlInitializeSizes.
%=============================================================================
%
%function sys=mdlGetTimeOfNextVarHit(t,x,u)
%sampleTime = 1; %Example, set the next hit to be one second later.
%sys = t + sampleTime;
% end mdlGetTimeOfNextVarHit
%
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%==========================================================================
%===
function sys=mdlTerminate(t,x,u)
sys = [];
错误信息如下:
Output argument "sys" (and maybe others) not assigned during call to "D:\MATLAB\R2009a\toolbox\simulink\blocks\emf.m>mdlOutputs".
% end mdlTerminate s函数一直用的少,搞不明白,感觉很复杂。
就提示来看,好像是sys必须赋值吧。 回复 2# yjhou
我也是刚用的啊,还有好多不是很了解
页:
[1]