MEX file that combines some fuzzy models in one.
MATLAB help:
% FUZCOMB Combines some fuzzy models in one.
%
% fuzcomb(Combined_Model_TXT,Model1, Model2,...)
%
% Combined_Model_FIS = fuzcomb(Model1, Model2,...)
%
% Arguments:
%
% Combined_Model_TXT -> String with the name of TXT file to write with the
% combined model. This file will be overwrited without
% confirmation.
%
% Combined_Model_FIS -> Variable 'FIS' to write the combined model.
%
% ModelX -> Fuzzy models to combine. These models must have the same number
% of inputs. They could be a '.txt' or '.fis' file, or a 'FIS'
% variable from MATLAB Workspace.
%
% To simulate this combined model should use 'fuzeval' function, 'evalfis'
% doesn't work correctly.
%
% See also activation, antec2mat, aproxjac, aproxlinear, conseq2mat, fis2txt,
% fuz2mat, fuzeval, fuzjac, fuzlinear, fuzprint, mat2antec, mat2conseq,
% mat2fuz, fuzsubsystem, txt2fis
Source code:
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
size_t i,j,r,s;
size_t sysnumber,in,outputs=0,*rules;
if (nlhs>1)
{
sprintf(error,"%s %s, %s",E_NumberArg,O_OfOut,U_SeeHelp);
}
if ((nlhs==0 && nrhs<3) || (nlhs==1 && nrhs<2))
{
sprintf(error,"%s, %s",E_NumberArg,U_SeeHelp);
}
int operationtype = 1 - nlhs;
sysnumber = nrhs - operationtype;
for (size_t i=0;i<nrhs;i++)
if (mxIsEmpty(prhs[i]) || mxIsNaN(*mxGetPr(prhs[i])))
for (i=operationtype;i<nrhs;i++)
{
{
mexPrintf("%s %d.\n",U_CheckModel,1+i-operationtype);
delete [] S;
}
if (i==operationtype)
{
}
else if (in!=S[i-operationtype].inputs())
{
delete [] S;
}
outputs += S[i-operationtype].
outputs();
}
rules = new size_t[outputs];
j = 0;
for (s=0;s<sysnumber;s++)
rules[j] = S[s].rules(i);
outputs = 0;
for (s=0;s<sysnumber;s++)
{
for (j=0;j<S[s].
outputs();j++,outputs++)
{
for (r=0;r<S[s].
rules(j);r++)
{
for (i=0;i<in;i++)
{
}
}
}
}
double *limitsmin =
new double[S[0].
inputs()];
double *limitsmax = new double[S[0].inputs()];
for (i=0;i<S[0].inputs();i++)
{
limitsmin[i] = S[0].in_low(i);
limitsmax[i] = S[0].in_high(i);
}
delete [] limitsmin;
delete [] limitsmax;
limitsmin = new double[outputs];
limitsmax = new double[outputs];
outputs=0;
for (s=0;s<sysnumber;s++)
{
for (j=0;j<S[s].outputs();j++,outputs++)
{
limitsmin[outputs] = S[s].out_low(j);
limitsmax[outputs] = S[s].out_high(j);
}
}
delete [] limitsmin;
delete [] limitsmax;
if (nlhs==0)
{
{
delete [] S;
delete Sall;
delete [] rules;
}
{
delete [] S;
delete Sall;
delete [] rules;
mexPrintf("??? Error using ==> fuzcomb\n%s\n%s %s\n",E_FileOutput,U_OR,E_NoValidFP);
}
}
else
{
const char* names[]={"name","type","andMethod","orMethod","defuzzMethod","impMethod","aggMethod","input","output","rule"};
mwSize dim[]={1,1};
plhs[0]=mxCreateStructArray(2,dim,10,names);
{
mxDestroyArray(plhs[0]);
delete [] S;
delete Sall;
delete [] rules;
}
}
delete [] S;
delete Sall;
delete [] rules;
}