03sihongwei 发表于 2009-2-13 14:40

s-function size超出问题

使用自定义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 = 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
    = 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 = 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.

yufeng 发表于 2009-2-18 08:15

不要动函数名 你那个flashadc是什么函数
页: [1]
查看完整版本: s-function size超出问题