error in s function

6 次查看(过去 30 天)
mina ahmadi
mina ahmadi 2015-7-8
Hello, I have problem with s-function of fuzzy type 2
I setup fuzzy type 2 toolbox on matlab 2013a
But I have this error after run my simulink :
Error in 'auto/Subsystem/S-Function'
while executing MATLAB S-function 'fuzzy2sfunction', flag = 0 (initialize), at start of simulation.
Caused by:
Attempt to reference field of non-structure array.
---------------------------------------------
And this is s-function :
function [sys,x0,str,ts] = fuzzy2sfunction(t,x,u,flag,fis)
%TIMESTWO S-function whose output is two times its input.
% This M-file illustrates how to construct an M-file S-function that
% computes an output value based upon its input. The output of this
% S-function is two times the input value:
%
% y = 2 * u;
%
% See sfuntmpl.m for a general S-function template.
%
% See also SFUNTMPL.
% Copyright (c) 1990-1998 by The MathWorks, Inc. All Rights Reserved.
% $Revision: 1.3 $
%
% Dispatch the flag. The switch function controls the calls to
% S-function routines at each simulation stage of the S-function.
%
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
% Initialize the states, sample times, and state ordering strings.
case 0
[sys,x0,str,ts]=mdlInitializeSizes(fis);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
% Return the outputs of the S-function block.
case 3
sys=mdlOutputs(t,x,u,fis);
%%%%%%%%%%%%%%%%%%%
% Unhandled flags %
%%%%%%%%%%%%%%%%%%%
% There are no termination tasks (flag=9) to be handled.
% Also, there are no continuous or discrete states,
% so flags 1,2, and 4 are not used, so return an emptyu
% matrix
case { 1, 2, 4, 9 }
sys=[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Unexpected flags (error handling)%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Return an error message for unhandled flag values.
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
% end timestwo
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts] = mdlInitializeSizes(fis)
% Call function simsizes to create the sizes structure.
sizes = simsizes;
% Load the sizes structure with the initialization information.
%sistembil=readfis2('fis');
NumInputs=length(fis.input);
NumOutputs=length(fis.output);
sizes.NumContStates= 0;
sizes.NumDiscStates= 0;
sizes.NumOutputs= NumOutputs;
sizes.NumInputs= NumInputs;
sizes.DirFeedthrough=1;
sizes.NumSampleTimes=1;
% Load the sys vector with the sizes information.
sys = simsizes(sizes);
%
x0 = []; % No continuous states
%
str = []; % No state ordering
%
ts = [-1 0]; % Inherited sample time
% End of mdlInitializeSizes.
%sistembil=readfis2('fisbilgi');
%NumInputs=length(sistembil.input);
%NumOutputs=length(sistembil.output);
% end mdlInitializeSizes
%
%=============================================================================
% mdlOutputs
% Return the output vector for the S-function
%=============================================================================
%
function sys = mdlOutputs(t,x,u,fis)
% sys = u * 2;
% yazi=num2str(u,2);
% u=str2num(yazi);
% u';
sys=ruleview2guisiz(u',fis);
% end mdlOutputs
Thanks in advance for all your attentions towards my request.
Regards

回答(1 个)

Umesh Kumar
Umesh Kumar 2022-5-11
my s function buillded but logic is not working what i need to do after build please let me know
  1 个评论
Walter Roberson
Walter Roberson 2022-5-11
You should create a new question, and include more information.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Fuzzy Logic in Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by