|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
使用自定义s-function模块时出现如下错误:Error in 'sflashADC_sihw/S-Function' while executing M-File S-function 'sflashADC', flag = 3 (output), at time 0. MATLAB error message:
Error using ==> colon
Maximum variable size allowed by the program is exceeded.
请高手不吝赐教。
另源程序如下:
function [sys,x0,str,ts] = sflashADC(t,x,u,flag,vref,b,r)
% Dispatch the flag. The switch function controls the calls to
% S-function routines at each simulation stage.
switch flag
case 0
[sys,x0,str,ts] = mdlInitializeSizes; % Initialization
case 3
sys = flashADC(t,x,u,vref,b,r); % Calculate outputs
case { 1, 2, 4, 9 }
sys = []; % Unused flags
otherwise
error(['Unhandled flag = ',num2str(flag)]); % Error handling
end;
% End of function timestwo.
%==============================================================
% Function mdlInitializeSizes initializes the states, sample
% times, state ordering strings (str), and sizes structure.
%==============================================================
function [sys,x0,str,ts] = mdlInitializeSizes
% Call function simsizes to create the sizes structure.
sizes = simsizes;
% Load the sizes structure with the initialization information.
sizes.NumContStates= 0;
sizes.NumDiscStates= 0;
sizes.NumOutputs= 1;
sizes.NumInputs= 1;
sizes.DirFeedthrough=1;
sizes.NumSampleTimes=1;
% Load the sys vector with the sizes information.
sys = simsizes(sizes);
%
x0 = []; % No continuous states
%
str = []; % No state ordering
%
ts = [-1 0]; % Inherited sample time
% End of mdlInitializeSizes.
%==============================================================
% Function mdlOutputs performs the calculations.
%==============================================================
function sys=flashADC(t,x,u,vref,b,r)
a=-((2^(b+r-1)-r-1)/2^b+r/2^(b+r))*vref:vref/2^b:((2^(b+r-1)-r-1)/2^b+r/2^(b+r))*vref;
for i=(1:(2^(b+r)-r-1))
if u<a(i)
break;
else continue;
end
end
sys=i-1;
% End of mdlOutputs. |
|