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