声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1564|回复: 1

[基本模块类] s-function size超出问题

[复制链接]
发表于 2009-2-13 14:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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.
回复
分享到:

使用道具 举报

发表于 2009-2-18 08:15 | 显示全部楼层
不要动函数名 你那个flashadc是什么函数
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-29 01:48 , Processed in 0.064379 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表