addRule
Add rule to fuzzy inference system
Description
Examples
Load a fuzzy inference system (FIS), and clear the existing rules.
fis = readfis("tipper");
fis.Rules = [];Add a rule to the FIS.
ruleTxt = "If service is poor then tip is cheap";
fis2 = addRule(fis,ruleTxt);fis2 is equivalent to fis, except that the specified rule is added to the rule base.
fis2.Rules
ans = 
  fisrule with properties:
    Description: "service==poor => tip=cheap (1)"
     Antecedent: [1 0]
     Consequent: 1
         Weight: 1
     Connection: 1
Load a fuzzy inference system (FIS).
fis = readfis("tipper");Specify if-then rules using linguistic expressions.
rule1 = "If service is poor or food is rancid then tip is cheap"; rule2 = "If service is excellent and food is not rancid then tip is generous"; rules = [rule1 rule2];
Add the rules to the FIS.
fis2 = addRule(fis,rules);
fis2 is equivalent to fis, except that the specified rules are added to the rule base.
Load a fuzzy inference system (FIS), and clear the existing rules.
fis = readfis("tipper");
fis.Rules = [];Specify the following rules using symbolic expressions:
- If - serviceis- pooror- foodis- rancidthen- tipis- cheap.
- If - serviceis- excellentand- foodis not- rancidthen- tipis- generous.
rule1 = "service==poor | food==rancid => tip=cheap"; rule2 = "service==excellent & food~=rancid => tip=generous"; rules = [rule1 rule2];
Add the rules to the FIS.
fis2 = addRule(fis,rules);
fis2 is equivalent to fis, except that the specified rules are added to the rule base.
fis2.Rules
ans = 
  1×2 fisrule array with properties:
    Description
    Antecedent
    Consequent
    Weight
    Connection
  Details:
                               Description                      
         _______________________________________________________
    1    "service==poor | food==rancid => tip=cheap (1)"        
    2    "service==excellent & food~=rancid => tip=generous (1)"
Load fuzzy inference system (FIS) and clear the existing rules.
fis = readfis("mam22.fis");
fis.Rules = [];Specify the following rules using membership function indices:
- If - angleis- smalland- velocityis- big, then- forceis- negBigand- force2is- posBig2.
- If - angleis not- smalland- velocityis- small, then- forceis- posSmalland- force2is- negSmall2.
rule1 = [1 2 1 4 1 1]; rule2 = [-1 1 3 2 1 1]; rules = [rule1; rule2];
Add the rules to the FIS.
fis2 = addRule(fis,rules);
fis2 is equivalent to fis, except that the specified rules are added to the rule base.
fis2.Rules
ans = 
  1×2 fisrule array with properties:
    Description
    Antecedent
    Consequent
    Weight
    Connection
  Details:
                                       Description                               
         ________________________________________________________________________
    1    "angle==small & velocity==big => force=negBig, force2=posBig2 (1)"      
    2    "angle~=small & velocity==small => force=posSmall, force2=negSmall2 (1)"
Input Arguments
Fuzzy inference system, specified as one of these objects:
- mamfis— Mamdani fuzzy inference system
- sugfis— Sugeno fuzzy inference system
- mamfistype2— Type-2 Mamdani fuzzy inference system
- sugfistype2— Type-2 Sugeno fuzzy inference system
Rule description, specified using either a text or numeric rule definition.
Text Rule Description
For a text rule description, specify ruleDescription as one
              of these values:
- String or character vector specifying a single rule. - rule = "If service is poor or food is rancid then tip is cheap";
- String array, where each element corresponds to a rule. - ruleList = ["If service is poor or food is rancid then tip is cheap"; "If service is good then tip is average"; "If service is excellent or food is delicious then tip is generous"]; 
- Character array where each row corresponds to a rule. - rule1 = 'If service is poor or food is rancid then tip is cheap'; rule2 = 'If service is good then tip is average'; rule3 = 'If service is excellent or food is delicious then tip is generous'; ruleList = char(rule1,rule2,rule3); 
For each rule, use one of the following rule text formats.
- Verbose — Linguistic expression in the following format, using the - IFand- THENkeywords:- "IF <antecedent> THEN <consequent> (<weight>)" - In - <antecedent>, specify the membership function for each input variable using the- ISor- IS NOTkeyword. Connect these conditions using the- ANDor- ORkeywords. If a rule does not use a given input variable, omit it from the antecedent.- In - <consequent>, specify the condition for each output variable using the- ISor- IS NOTkeyword, and separate these conditions using commas. The- IS NOTkeyword is not supported for Sugeno outputs. If a rule does not use a given output variable, omit it from the consequent.- Specify the weight using a positive numerical value. - "IF A IS a AND B IS NOT b THEN X IS x, Y IS NOT y (1)" 
- Symbolic — Expression that uses the symbols in the following table instead of keywords. There is no symbol for the - IFkeyword.- Symbol - Keyword - ==- IS(in rule antecedent)- ~=- IS NOT- &- AND- |- OR- =>- THEN- =- IS(in rule consequent)- For example, the following symbolic rule is equivalent to the previous verbose rule. - "A==a & B~=b => X=x, Y~=y (1)" 
Numeric Rule Description
For a numeric rule description, specify ruleDescription as
              one of these values:
- Row vector to specify a single fuzzy rule 
- Array, where each row of - ruleValuesspecifies one rule
For each row, the numeric rule description has M+N+2 columns, where M is the number of input variables and N is the number of output variables. Each column contains the following information:
- The first M columns specify input membership function indices and correspond to the - Antecedentproperty of the rule. To indicate a- NOTcondition, specify a negative value. If a rule does not use a given input, set the corresponding index to- 0. For each rule, at least one input membership function index must be nonzero.
- The next N columns specify output membership function indices and correspond to the - Consequentproperty of the rule. To indicate a- NOTcondition for Mamdani systems, specify a negative value.- NOTconditions are not supported for Sugeno outputs. If a rule does not use a given output, set the corresponding index to- 0. For each rule, at least one output membership function index must be nonzero.
- Column M+N+1 specifies the rule weight and corresponds to the - Weightproperty of the rule.
- The final column specifies the antecedent fuzzy operator and corresponds to the - Connectionproperty of the rule.
Version History
Introduced in R2018baddRule no longer supports fuzzy inference system structures.
        Use mamfis and sugfis objects
        instead. To convert existing fuzzy inference system structures to objects, use the convertfis function.
Support for fuzzy inference systems structures will be removed in a future release. This
        change was announced in R2018b. Using fuzzy inference system structures with
          addRule issues a warning starting in R2019b.
addrule is now addRule. To update your code,
        change the function name from addrule to addRule.
        The syntaxes are equivalent.
You can add rules to a fuzzy system using linguistic and symbolic expressions. This
          addRule functionality replaces the equivalent parsrule functionality.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)