MEX file that performs fuzzy inference calculations of open/closed loop fuzzy system.
MATLAB help:
% FUZEVAL Performs fuzzy inference calculation of open/closed loop fuzzy system.
%
% Output = fuzeval(X_U,Fuzzy_Model)
%
% Output = fuzeval(X,Plant,Controller)
%
% X_U -> Input vector: [X;U] = [x1;x2;...;xn;u1;u2;...;um]
%
% X -> State vector.
%
% Plant -> Fuzzy model of the Plant.
%
% Controller -> Fuzzy model of the Controller.
%
% Fuzzy_Model -> This fuzzy model could be a '.txt' file, a '.fis' file,
% or a 'FIS' variable from MATLAB Workspace.
%
% See also activation, antec2mat, aproxjac, aproxlinear, conseq2mat, fis2txt,
% fuz2mat, fuzcomb, fuzjac, fuzlinear, fuzprint, mat2antec, mat2conseq,
% mat2fuz, fuzsubsystem, txt2fis
Source code:
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
size_t i;
int ode = 0;
if(nrhs<2 || nrhs>4)
if (nlhs>1)
for (i=0;i<nrhs;i++)
{
if (mxIsEmpty(prhs[i]) || mxIsNaN(*mxGetPr(prhs[i])))
}
double *X;
Array1D<double> dX;
if (nrhs!=2 && mxGetN(prhs[0])==1 && mxGetM(prhs[0])==1 && mxIsStruct(prhs[1])==false && mxIsChar(prhs[1])==false)
ode = 1;
X = mxGetPr(prhs[ode]);
if (!X)
if (mxGetN(prhs[ode])!=1)
{
mexPrintf("%s %s.\n",U_CheckModel,O_OfPlant);
}
plhs[0] = mxCreateDoubleMatrix(S.
outputs(),1,mxREAL);
if (!plhs[0])
if (nrhs==(2+ode))
{
if (mxGetM(prhs[ode])!=S.
inputs())
{
mxDestroyArray(plhs[0]);
}
if(!dX.dim())
{
mxDestroyArray(plhs[0]);
mexPrintf("Fuzeval. %s\b or %s\n",U_Overflow,E_NoCoherent);
mexErrMsgTxt("");
return;
}
}
else
{
if (mxGetM(prhs[ode])!=S.
outputs())
{
mxDestroyArray(plhs[0]);
}
{
mxDestroyArray(plhs[0]);
mexPrintf("%s %s.\n",U_CheckModel,O_OfController);
}
if (!dX.dim())
{
if (!error)
{
mxDestroyArray(plhs[0]);
}
else
{
mxDestroyArray(plhs[0]);
mexPrintf("Fuzeval. %s or",U_Overflow);
}
}
}
double *MATLABOut = mxGetPr(plhs[0]);
for (i=0;i<dX.dim();i++)
MATLABOut[i] = dX[i];
}