Fuzzy Logic Toolbox | ![]() ![]() |
Customizing Your Fuzzy System
If you want to include customized functions as part of your use of the Fuzzy Logic Toolbox, there are a few guidelines you need to follow. The AND method, OR method, aggregation method, and defuzzification method functions you provide need to 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. For example, the implication method does an element by element matrix operation, similar to the min function, as in
a=[1 2; 3 4]; b=[2 2; 2 2]; min(a,b) ans = 1 2 2 2
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 at most 16 parameters.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 | ![]() |