|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
我最近在编一个s函数,源代码如下:
function [y0,x0,str,ts] =panduan(t,x,u0,flag)
% S-file example 1
% This is an S-file subsystem with no states. It performs
% the algebraic function y = u(1) + u(2)^2. There are two
% inputs and one output.
%
% Based on sfuntmpl.m, supplied with SIMULINK
% Copyright (c) 1990-96 by The MathWorks, Inc.
%
switch flag
case 0 % Initialization
[y0,x0,str,ts]=mdlInitializeSizes();
case 1 % Compute derivatives of continuous states
y0=mdlDerivatives(t,x,u0);
case 2
y0=mdlUpdate(t,x,u0);
case 3
y0=mdlOutputs(t,x,u0); % Compute output vector
%case 4 % Compute time of next sample
%sys=mdlGetTimeOfNextVarHit(t,x,u);
%case 9 % Finished. Do any needed
%sys=mdlTerminate(t,x,u);
%otherwise % Invalid input
% error(['Unhandled flag = ',num2str(flag)]);
end;
%***************************************************************
%* mdlInitializeSizes *
%***************************************************************
function [y0,x0,str,ts]=mdlInitializeSizes()
% Return the sizes of the system vectors, initial conditions, and
% the sample times and offets.
sizes = simsizes; % Create the sizes structure
sizes.NumContStates = 0;
sizes.NumDiscStates = 3;
sizes.NumOutputs = 1;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
y0 = simsizes(sizes); % load sys with the sizes structure
x0 = [1;1;0]; % Specify initial conditions for all states
str = []; % str is always an empty matrix
ts = [0 0]; %initialize the array of sample times
%***************************************************************
%* mdlDerivatives *
%***************************************************************
function y0=mdlDerivatives(t,x,u0)
% Compute derivatives of continuous states
sys = []; % Empty since this S-file has no continuous states
%***************************************************************
%* mdlUpdate *
%***************************************************************
function y0=mdlUpdate(t,x,u0)
% Compute update for discrete states. If necessary, check for
% sample time hits.
if u0>=2
x(1)=x(1)+1;
x(2)=x(1);
x(3)=1
y0=[x(1);x(2);x(3)];
else if x(2)>1&&u0<2
x(3)=1
y0=[x(1);x(2);x(3)];
else
x(3)=0
y0=[x(1);x(2);x(3)];
end
end
%***************************************************************
%* mdlOutputs *
%* Output compensation torque to nonlinear friction *
%***************************************************************
function y0=mdlOutputs(t,x,u0)
y0=x(3);
在s-function builder里面编译之后
出现如下问题:
kaiguan0.obj : error LNK2001: unresolved external symbol _panduan_Outputs_wrapper
kaiguan0.obj : error LNK2001: unresolved external symbol _panduan_Update_wrapper
kaiguan0.dll : fatal error LNK1120: 2 unresolved externals
NMAKE : fatal error U1077: 'link' : return code '0x460'
Stop.
希望哪位老师能给我一点指点,不胜感激!!!!!!!!! |
|