MEX file that extracts all data from a fuzzy model.
MATLAB help:
% FUZ2MAT Extracts all data from a fuzzy model.
%
% Vector = fuz2mat(Fuzzy_Model)
%
% Vector = fuz2mat(Fuzzy_Model,Output,Rule)
%
% [Vector, length] = fuz2mat(Fuzzy_Model)
%
% [Vector, length] = fuz2mat(Fuzzy_Model,Output,Rule)
%
% Arguments:
%
% Vector -> Vector with data from fuzzy model.
%
% Output -> Use to select the output.
%
% Rule -> Use to select the rule for given output.
%
% length -> The length of Vector, 0 if error.
%
% Fuzzy_Model -> This model could be a '.txt' file, a '.fis' file or a
% 'FIS' variable from MATLAB Workspace.
%
% See also activation, antec2mat, aproxjac, aproxlinear, conseq2mat, fis2txt,
% fuzcomb, 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, length, out, rule;
double *data;
if(nrhs<1)
if (nrhs>1)
{
if (nrhs!=3)
if (mxGetM(prhs[1])>1 || mxGetM(prhs[2])>1)
if (mxGetN(prhs[1])!=mxGetN(prhs[2]))
}
if (nlhs>2)
if (mxIsEmpty(prhs[0]) || mxIsNaN(*mxGetPr(prhs[0])))
if (nrhs==1)
{
}
else
{
length = 0;
for (i=0;i<mxGetN(prhs[2]);i++)
{
out = ((size_t)*(mxGetPr(prhs[1])))-1;
rule = ((size_t)*(mxGetPr(prhs[2])))-1;
size_t numAntec = S.
readRule(out, rule)->NumberOfAntecedents();
length += numAntec + NoC;
}
}
Array1D<double> Data(length);
if (nrhs==1)
{
for (size_t d=0;d<AntecData.dim();d++)
Data[d] = AntecData[d];
for (size_t d=0;d<ConseqData.dim();d++)
Data[AntecData.dim()+d] = ConseqData[d];
}
else
{
size_t dataIdx = 0;
for (i=0;i<mxGetN(prhs[2]);i++)
{
out = ((size_t)*(mxGetPr(prhs[1])))-1;
rule = ((size_t)*(mxGetPr(prhs[2])))-1;
for (size_t d=0;d<AntecData.dim();d++, dataIdx++)
Data[dataIdx] = AntecData[d];
for (size_t d=0;d<ConseqData.dim();d++, dataIdx++)
Data[dataIdx] = ConseqData[d];
}
}
plhs[0] = mxCreateDoubleMatrix(length,1,mxREAL);
double *MATLABData = mxGetPr(plhs[0]);
for (i=0; i<length; i++)
MATLABData[i] = Data[i];
if (nlhs==2)
plhs[1] = mxCreateDoubleScalar(length);
if (length==0)
{
if (nlhs==1)
else
plhs[0] = mxCreateDoubleMatrix(0,0,mxREAL);
}
}