Fuzzy Logic Tools  v1.0.5.1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
matlab_utilities/mat2conseq.cpp

MEX file that changes the consequent of a fuzzy model.

MATLAB help:

% MAT2CONSEQ Changes the consequent of a fuzzy model.
%
% Final_Model = mat2conseq(Initial_Model,Vector)
%
% Final_Model = mat2conseq(Initial_Model,Vector,Output,Rule)
%
% [Final_Model,length] = mat2conseq(Initial_Model,Vector)
%
% [Final_Model,length] = mat2conseq(Initial_Model,Vector,Output,Rule)
%
% Arguments:
%
% Final_Model -> Changed fuzzy model.
%
% Output -> Use to select the consequent of one output.
%
% Rule -> Use to select the consequent of one rule for given output.
%
% length -> The length of Vector, 0 if error.
%
% Initial_Model -> Fuzzy Model to change. This model could be a '.txt' file,
% a '.fis' file, or a 'FIS' variable from MATLAB Workspace.
%
% Vector -> Vector with data for fuzzy model consequent.
%
% See also activation, antec2mat, aproxjac, aproxlinear, conseq2mat, fis2txt,
% fuz2mat, fuzcomb, fuzeval, fuzjac, fuzlinear, fuzprint, mat2antec,
% mat2fuz, fuzsubsystem, txt2fis

Source code:

/* Copyright (C) 2004-2011
ANTONIO JAVIER BARRAGAN, antonio.barragan@diesia.uhu.es
http://uhu.es/antonio.barragan
Collaborators:
JOSE MANUEL ANDUJAR, andujar@diesia.uhu.es
MARIANO J. AZNAR, marianojose.aznar@alu.uhu.es
DPTO. DE ING. ELECTRONICA, DE SISTEMAS INFORMATICOS Y AUTOMATICA
ETSI, UNIVERSITY OF HUELVA (SPAIN)
For more information, please contact with authors.
This software is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "aux_matlab.hpp"
using namespace FLT;
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
size_t i, n_con, out,rule;
double *data;
if(nrhs<2)
ERRORMSG(E_NumberArgIn)
if (nrhs>2 && nrhs!=4)
ERRORMSG(E_NumberArgIn)
if (nlhs>2)
ERRORMSG(E_NumberArgOut)
if (mxIsEmpty(prhs[0]) || mxIsNaN(*mxGetPr(prhs[0])))
ERRORMSG(E_ArgNoValid)
if (nrhs==4)
{
if (mxGetM(prhs[2])>1 || mxGetM(prhs[3])>1)
ERRORMSG(E_RuleOutputFileVector)
if (mxGetN(prhs[2])!=mxGetN(prhs[3]))
ERRORMSG(E_NumberArg)
}
System S;
if (readModel(prhs[0],S))
ERRORMSG(E_Model)
size_t NoC = S.inputs() + 1;
if (nlhs==2)
{
if (nrhs==2)
{
n_con = S.NumberOfConsequents();
}
else
{
n_con = 0;
for (i=0;i<mxGetN(prhs[2]);i++)
{
out = ((size_t)*(mxGetPr(prhs[2])+i))-1; // MATLAB is index-1 but C/C++ is index-0
rule = ((size_t)*(mxGetPr(prhs[3])+i))-1;
n_con += NoC;
}
}
if (!n_con)
ERRORMSG(E_BadModel)
}
// Save data in S
data = mxGetPr(prhs[1]);
if (nrhs==2)
S.setConsequents(data);
else
{
for (i=0;i<mxGetN(prhs[2]);i++)
{
out = ((size_t)*(mxGetPr(prhs[2])+i))-1;
rule = ((size_t)*(mxGetPr(prhs[3])+i))-1;
S.readRule(out,rule)->setConsequents(data+NoC*i);
}
}
if (nlhs==2)
plhs[1] = mxCreateDoubleScalar(n_con);
// Create the FIS variable
const char* names[] = {"name","type","andMethod","orMethod","defuzzMethod","impMethod","aggMethod","input","output","rule"};
mwSize dim[] = {1,1};
plhs[0]= mxCreateStructArray(2,dim,10,names);
if(System2FIS(S, plhs[0]))
{
mxDestroyArray(plhs[0]);
ERRORMSG(E_CreateFIS)
}
}