S-function Error cuase?

1 次查看(过去 30 天)
moha
moha 2014-8-27
编辑: moha 2014-8-28
Hello every one I have a model in simulink :
S-Function :
if true
function [sys,x0,str,ts] = pt1sfun(t,x,u,flag,T)
A = [-1/T];
B = [ 1/T];
C = [ 1 ];
D = [ 0 ];
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(A,B,C,D);
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
case 1,
sys=mdlDerivatives(t,x,u,A,B,C,D);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u,A,B,C,D);
% Nicht verwendete Flags
case {2, 4, 9},
sys=[];
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise % Fehlerbehandlung
error(['Unhandled flag = ',num2str(flag)]);
%end
% end pt1sfun
%
%=============================================================================
% mdlInitializeSizes
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes(A,B,C,D)
sizes = simsizes;
sizes.NumContStates = size(A,1);
sizes.NumDiscStates = 0;
sizes.NumOutputs = size(C,1);
sizes.NumInputs = size(B,1);
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
% initialize the initial conditions
x0 = zeros(size(A,1),1); % Anfangszustand: x0 = 0
% str is always an empty matrix
str = [];
%
% initialize the array of sample times; in diesem Beispiel ist die
% Abtastzeit kontinuierlich, daher wird ts und der zugehoerige
% Offset zu Null gesetzt.
%
ts = [0 0];
% end mdlInitializeSizes
%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys=mdlDerivatives(t,x,u,A,B,C,D)
sys = A*x + B*u; % Berechnung von der Ableitungen xpunkt
% end mdlDerivatives
%%=============================================================================
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u,A,B,C,D)
sys = C*x + D*u; % Berechnung des Ausgangsvektors y
% end mdlOutputs
end
I got this error after running;Why?
.. ..
Here T is fix(T = 0.01;)
Another question: If T be variable (0.1<T<10) from another part of simulink How can I define T in S-Function?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Block and Blockset Authoring 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by