This file contains instructions on how to build the MATLAB DLL example 
fuzzy.dll.  This example builds a Windows DLL to implement the function 
"fuzzy" in Matlab.  These instructions do not apply to building a 32-bit
MEX file to implement the "fuzzy" function.

This example was developed and tested using MS-C 7.0, Matlab 4.0
and Simulink 1.2c for Windows 3.1.

The function "fuzzy" requires two scalar arguments as inputs, and returns a 
single scalar value as its output.

1.  Build the fcdslibw.lib library for use in a DLL using the makefile
    provided in \SIEFUZZY\LIBSRC. Then make sure your linker searches the
    directory \SIEFUZZY\LIBSRC for library files to use during the link.

2.  The files mlpend.c and mlpend.h define a slight alteration of the simple
    inverted pendulum example. 

3.  Open the file fuzzy.c to examine the MATLAB DLL interface code 
    which calls the MATLAB mexFunction.  Notice that mex.h and mlpend.h are
    #include'd in the file.  Also notice the use of the mxGetPr function to
    get pointers to the variables needed to be passed to the fuzzy system.

4.  Use either the batch file CMEX.BAT in your \MATLAB\BIN directory or the
    supplied makefile to build the DLL.  If you use the file CMEX.BAT, be sure
    to edit it first, setting the necessary paths to your C compiler, Matlab,
    etc.  Also, you may want to add the command line option -DANSI to the
    other options if you are using an ANSI C compiler.
    If you use the example makefile, change your INCLUDE and LIB environment 
    variables to include the MATLAB\EXTERN\LIB and \INCLUDE directories.
    
    The command line for cmex.bat is:

	  cmex fuzzy.c mlpend.c

    The command line for using the makefile is:

	  nmake


5.  Once the DLL has been successfully compiled, either copy the DLL into a
    directory in the Matlab path, or change the Matlab path to include the 
    DLL's directory.  (Type "help path" in Matlab for instructions on changing
    Matlab's path).

6.  Once Matlab can find the DLL, the function "fuzzy" will be available 
    directly from within Matlab.  An example call is given below:

    x = fuzzy( 0.1, 0.2), the general form being output = fuzzy(Error, dError)

    The range of Error and dError are limited to [-1,1].


STOP HERE IF YOU DON'T HAVE SIMULINK

7.  The file sfuzzym.m is provided to make the fuzzy function available from 
    within Simulink.  Open the file sfuzzym.m to examine the code.  It is 
    based on the limintm.m Simulink example.

8.  To add the fuzzy function to a Simulink file, add an S-function block from
    the Nonlinear library, and then double-click on it to edit its 
    description.  Change the Subsystem function name to sfuzzym.  There are
    no parameters to pass to the function.

9.  You will need a multiplexer in front of the sfuzzym block to combine the
    two inputs Error and dError to a single input line.  The output can only
    be connected to something expecting a single output value.

10. For a complete example of using the sfuzzym function in Simulink, open 
    Simulink, and then open the file pendmodl.m.  This file contains a simple
    model of the inverted pendulum system with adjustable parameters, a fuzzy
    controller subsystem using sfuzzym, a PID controller, and several scopes 
    to observe the system.  The constant "Controller Switch" can be changed to
    select between the two controllers.  A value >= 0 selects the Fuzzy 
    controller, and a vlaue < 0 selects the PID controller.  The outputs of 
    the two controllers may be compared in the scopes "Fuzzy Current" and
    "PID Current".  The constants for the motorsize, mass, and length may
    be changed in the various blocks of the Pendulum model subsystem.
