How can I solve this S-function problem?

3 views (last 30 days)
Silvia
Silvia on 3 Jun 2014
Hy, I have a problem with my S-function. I got this error Could anybody help me pls Error: Error evaluating parameter '[t,x,u,flag,ni,n,p,q,fuzzy_m,Ts,x_0]' in 'Model_nou_fuzzyd_date3/S-Function Modelul dinamic Takagi-Sugeno al procesului condus'
Caused by: Undefined function or variable 'x'.
This is my code:
function [sys,x0,str,ts] = S_mod_fuz_procd(ni,n,p,q,fuzzy_m,Ts,x_0) % S-function for defining a dynamic Takagi-Sugeno fuzzy model of a discrete-time system % x' = Sum[(h_i(z))(A_i x + B_i u) % y = Sum[(h_i(z))(C_i x + D_i u)] % The dynamic fuzzy model is given in the variable fuzzy_m (FIS)
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(ni,n,p,q,fuzzy_m,Ts,x_0);
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys=mdlUpdate(t,x,u,ni,n,p,q,fuzzy_m,Ts);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u,ni,n,p,q,fuzzy_m,Ts);
%%%%%%%%%%%%%%%%%%%
% Unhandled flags %
%%%%%%%%%%%%%%%%%%%
case { 1, 4, 9 },
sys = [];
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end % end csfunc
% %============================================================================= % mdlInitializeSizes % Return the sizes, initial conditions, and sample times for the S-function. %============================================================================= % function [sys,x0,str,ts]=mdlInitializeSizes(ni,n,p,q,fuzzy_m,Ts,x_0)
sizes = simsizes; sizes.NumContStates = 0; sizes.NumDiscStates = n; sizes.NumOutputs = q+n; % Additional outputs: the first q outputs correspond to system's outputs and the rest of n % outputs corespond to system's state variables: sizes.NumInputs = ni+p; sizes.DirFeedthrough = 1; sizes.NumSampleTimes = 1;
sys = simsizes(sizes); x0=x_0; str = []; ts = [Ts 0];
% end mdlInitializeSizes % %============================================================================= % mdlUpdate % Handle discrete state updates, sample time hits, and major time step % requirements. %============================================================================= % function sys=mdlUpdate(t,x,u,ni,n,p,q,fuzzy_m,Ts)
outfuz=evalfis([u' x'],fuzzy_m)';
sys = outfuz(1:n,1); ccc=isnan(sys); [mm1 mm2]=size(ccc); if ccc~=zeros(mm1,mm2), sys=zeros(mm1,mm2); end
% end mdlUpdate % %============================================================================= % mdlOutputs % Return the block outputs. %============================================================================= % function sys=mdlOutputs(t,x,u,ni,n,p,q,fuzzy_m,Ts)
outfuz=evalfis([u' x'],fuzzy_m)';
sys=zeros(q+n,1); % Initial value of output vector
ddd = outfuz(n+1:n+q,1); ccc=isnan(ddd); [mm1 mm2]=size(ddd); if ccc~=zeros(mm1,mm2), ddd=zeros(mm1,mm2); end
% The first q outputs correspond to system's outputs and the rest of n % outputs corespond to system's state variables:
sys(1:q,1)=ddd;
sys(q+1:q+n,1)=x;
% end mdlOutputs

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!