Skip to Main Content Skip to Search
Product Documentation

Simulating Fuzzy Inference Systems Using the Fuzzy Inference Engine

Uses of the Fuzzy Inference Engine

Fuzzy Logic Toolbox software provides a stand-alone C code fuzzy inference engine. You can use the engine as an alternative tool to simulate the outputs of your fuzzy inference system (FIS), without using the MATLAB environment. You can perform the following tasks using the fuzzy inference engine:

About the Fuzzy Inference Engine

The stand-alone fuzzy inference engine consists of two C code source files fismain.c and fis.c in the matlabroot\toolbox\fuzzy\fuzzy folder.

The fismain.c file contains only the main() function and you can easily modify it to adapt to other applications. It is ANSI Ccompatible, and you can compile it with any ANSI Ccompiler.

The fis.c file contains all the necessary functions to perform the fuzzy inference process:

The fismain executable code, generated after compiling the source codes, reads an input data file and a FIS structure file to simulate the output. The syntax for calling fismain is similar to its MEX-file counterpart evalfis, except that all matrices are replaced with files. To learn more about evalfis, see the evalfis function reference page.

Example — Using the Fuzzy Inference Engine on Windows Platforms

This example demonstrates how to simulate a fuzzy inference system on a Windows® platform using the stand-alone fuzzy inference engine. In this example, you use the LCC C compiler shipped with MATLAB to compile the fuzzy inference engine source codes.

  1. Open a DOS Command Window and change the folder to matlabroot\toolbox\fuzzy\fuzzy.

      Tip   You can find the root folder of your MATLAB installation by typing matlabroot at the MATLAB command prompt.

  2. In the DOS Command Window, type the following command:

    lcc -c fismain.c

    This command creates the fismain.obj object file in the matlabroot\toolbox\fuzzy\fuzzy folder.

  3. In the DOS Command Window, type the following command:

    lcclnk fismain.obj.

    This command creates an executable file fismain.exe in the matlabroot\toolbox\fuzzy\fuzzy folder.

  4. Open MATLAB desktop, and change to your current working folder using the Current Folder field in the MATLAB desktop toolbar.

  5. At the MATLAB prompt, type the following command to create an input data file:

    [x, y] = meshgrid(-5:5, -5:5);
    input_data = [x(:) y(:)];
    save fis_in input_data -ascii
    

    This command saves the input data as a 121-by-2 matrix in the fis_in ASCII file in your current working folder. Each row of the matrix represents an input vector.

  6. Copy the FIS structure file mam21.fis from the matlabroot\toolbox\fuzzy\fuzdemos folder to your current working folder.

  7. Copy the stand-alone executable file fismain.exe from the matlabroot\toolbox\fuzzy\fuzzy folder to your current working folder.

  8. In the DOS Command Window, change the folder to your current working folder, and type the following command to call the stand-alone executable code:

    fismain fis_in mam21.fis

    This command uses the data file fis_in and the FIS structure file mam21.fis, and generates 121 outputs on your screen.

      Tip   You can also direct the outputs to a file using the following command in the DOS Command Window:

      fismain fis_in mam21.fis > fis_out
      

      This command saves the output data fis_out as a 121-by-1 matrix in your current working folder. Each row of the output matrix represents an output vector.

  9. To verify that the fuzzy inference engine output matches the MATLAB MEX-file evalfis.m output, type the following command at the MATLAB prompt:

    fismat = readfis('mam21');
    matlab_out = evalfis(input_data, fismat);
    load fis_out
    max(max(matlab_out - fis_out))
    

    This command returns the following result:

    ans =
    
      4.9583e-013

    The difference results from the relative precision between the outputs.

Including the lcc Command in the PATH Environment Variable

When executing the lcc command to create the fismain.obj object file, you get the following error if the command and/or the path for the <include> header files are not in the PATH environment variable:

'lcc' is not recognized as an internal or external command, operable program or batch file.

To include the command in the PATH environment variable, type the following in the DOS Command Window:

matlabroot\sys\lcc\bin\lcc -Imatlabroot\sys\lcc\include fismain.c

Press Enter when prompted to Please enter the path for the <include> header files.

Including the lcclnk Command in the PATH Environment Variable

When executing the lcclnk command to create the fismain.exe file, you get the following error if the command is not in the PATH environment variable:

'lcclnk' is not recognized as an internal or external command, operable program or batch file.

To include the command in the PATH environment variable, type the following in the DOS Command Window:

matlabroot\sys\lcc\bin\lcclnk fismain.obj

Example — Using the Fuzzy Inference Engine on UNIX Platforms

This example demonstrates how to simulate a fuzzy inference system on a UNIX® platform using the stand-alone fuzzy inference engine.

  1. Open a UNIX Command Window and change the folder to matlabroot\toolbox\fuzzy\fuzzy.

      Tip   You can find the root folder of your MATLAB installation by typing matlabroot at the MATLAB command prompt.

  2. In the UNIX Command Window, type the following command:

    	cc -O -o fismain fismain.c -lm
    

    This command creates the fismain file in the matlabroot\toolbox\fuzzy\fuzzy folder.

    The fis.c file is included in the fismain.c file; you do not have to compile it separately.

  3. At the MATLAB prompt, create an input data file using the following command:

    [x, y] = meshgrid(-5:5, -5:5);
    input_data = [x(:) y(:)];
    save fis_in input_data -ascii
    

    This command saves the input data as a 121-by-2 matrix in the ASCII file fis_in in your current working folder. Each row of the matrix represents an input vector.

      Tip   You can find your current working folder in the Current Folder field in the MATLAB desktop toolbar.

  4. Copy the FIS structure file mam21.fis from the matlabroot\toolbox\fuzzy\fuzdemos folder to your current working folder.

  5. Copy the fismain file from the matlabroot\toolbox\fuzzy\fuzzy folder to your current working folder.

  6. In the UNIX Command Window, change the folder to your current working folder, and type the following executable command:

    fismain fis_in mam21.fis
    

    This command uses the data file fis_in and the FIS structure file mam21.fis and generates 121 outputs on your screen.

      Tip   You can also direct the outputs to another file using the following command in the DOS Command Window:

      fismain fis_in mam21.fis > fis_out
      

      This command saves the output data fis_out as a 121-by-1 matrix in your current working folder. Each row of the output matrix represents an output vector.

  7. To verify that the fuzzy inference engine output matches the MATLAB MEX-file evalfis.m output, type the following command at the MATLAB prompt:

    fismat = readfis('mam21');
    matlab_out = evalfis(input_data, fismat);
    load fis_out
    max(max(matlab_out - fis_out))
    

    This command returns the following result:

    ans =
    
      4.9583e-013

    The difference results from the relative precision between the outputs.

  


Free Control Systems Interactive Kit

Learn more about resources for designing, testing, and implementing control systems.

Get free kit

Trials Available

Try the latest control systems products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS