Clear Filters
Clear Filters

S-function Error cuase?

1 view (last 30 days)
moha
moha on 27 Aug 2014
Edited: moha on 28 Aug 2014
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?

Answers (0)

Categories

Find more on Block and Blockset Authoring in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!