error in s function

조회 수: 6 (최근 30일)
mina ahmadi
mina ahmadi 2015년 7월 8일
댓글: Walter Roberson 2022년 5월 11일
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