Sunteți pe pagina 1din 4

Simulating Fuzzy Inference Systems Using the Fuzzy Inference Engine ::...

1 of 4

jar:file:///C:/Program%20Files/MATLAB/R2011a/help/toolbox/fuzzy/hel...

Simulating Fuzzy Inference Systems Using the Fuzzy Inference Engine


On this page
Uses of the Fuzzy Inference Engine
About the Fuzzy Inference Engine
Example Using the Fuzzy Inference Engine on Windows Platforms
Example Using the Fuzzy Inference Engine on UNIX Platforms

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:
Perform fuzzy inference using a FIS structure file and an input data file.
To learn more about how to create a FIS structure file, see Building Systems with Fuzzy Logic Toolbox Software.
Customize the fuzzy inference engine to include your own membership functions.
Embed the executable code in other external applications.
Back to Top

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 C compatible, and you can compile it with any ANSI C compiler.
The fis.c file contains all the necessary functions to perform the fuzzy inference process:
This file provides the 11 Fuzzy Logic Toolbox membership functions with their default settings.
You can add a new membership function or new reasoning mechanism by updating the fis.c file.
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.
Back to Top

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.
Note You may encounter the following error when executing the lcc command:
'lcc' is not recognized as an internal or external command, operable program

28/7/2558 12:33

Simulating Fuzzy Inference Systems Using the Fuzzy Inference Engine ::...

2 of 4

jar:file:///C:/Program%20Files/MATLAB/R2011a/help/toolbox/fuzzy/hel...

or batch file.
To learn how to troubleshoot this error, see the Including the lcc Command in the PATH Environment
Variable section.
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.
Note You may encounter the following error when executing the lcclnk command:
'lcclnk' is not recognized as an internal or external command, operable
program or batch file .
To learn how to troubleshoot this error, see the Including the lcclnk Command in the PATH Environment
Variable section.
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:

28/7/2558 12:33

Simulating Fuzzy Inference Systems Using the Fuzzy Inference Engine ::...

3 of 4

jar:file:///C:/Program%20Files/MATLAB/R2011a/help/toolbox/fuzzy/hel...

'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 -I matlabroot\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
Back to Top

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:

28/7/2558 12:33

Simulating Fuzzy Inference Systems Using the Fuzzy Inference Engine ::...

4 of 4

jar:file:///C:/Program%20Files/MATLAB/R2011a/help/toolbox/fuzzy/hel...

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.
Back to Top
Was this topic helpful?

Fuzzy Clustering

1984-2011 The MathWorks, Inc.

Yes

No

Function Reference

Terms of Use

Patents

Trademarks

Acknowledgments

28/7/2558 12:33

S-ar putea să vă placă și