Fuzzy Logic Toolbox | ![]() ![]() |
Customizing Your Fuzzy System
If you want to include customized functions as part of your use of the Fuzzy Logic Toolbox, you must follow a few guidelines. You may substitute customized functions for the AND, OR, aggregation, and defuzzification methods, provided your customized functions work in a similar way to max
, min
, or prod
in MATLAB. That is, they must be able to operate down the columns of a matrix.
In MATLAB, for a matrix x, min(x)
returns a row vector containing the minimum element from each column. For N-D arrays, min(x)
operates along the first non-singleton dimension. The function min(x,y)
, on the other hand, returns an array the same size as x
and y
populated with the smallest elements from x
or y
. Either one can be a scalar. Functions such as max, prod
, and mean
operate in a similar manner.
In the Fuzzy Logic Toolbox, the implication method performs an element by element matrix operation, similar to the min(x,y)
function in MATLAB, as in
After you have defined your custom function using the procedure described in the next section, use the FIS Editor to substitute your custom function for a standard function. To do this,
fuzzy
at the command line prompt.
Custom
. A dialog box appears.
Your custom function then replaces the standard function in all subsequent operations.
Custom Membership Functions
You can create your own membership functions using an M-file. The values these functions can take must be between 0 and 1. There is a limitation on customized membership functions in that they cannot use more than 16 parameters.
To define a custom membership function named custmf
custmf.m
, that takes values between 0 and 1, and depends on 16 parameters at most.
Add Custom MF
item in the Edit
menu on the Membership Function Editor GUI.
custmf
, in the M-file function name text box.
Here is some sample code for a custom membership function, testmf1
, that depends on eight parameters between 0 and 10.
function out = testmf1(x, params) for i=1:length(x) if x(i)<params(1) y(i)=params(1); elseif x(i)<params(2) y(i)=params(2); elseif x(i)<params(3) y(i)=params(3); elseif x(i)<params(4) y(i)=params(4); elseif x(i)<params(5) y(i)=params(5); elseif x(i)<params(6) y(i)=params(6); elseif x(i)<params(7) y(i)=params(7); elseif x(i)<params(8) y(i)=params(8); else y(i)=0; end end out=.1*y';
You can try naming this file testmf1.m
and loading it into the Membership Function Editor using the parameters of your choice.
![]() | Importing and Exporting from the GUI Tools | Working from the Command Line | ![]() |