# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

Add rule to fuzzy inference system

## Syntax

```fis = addrule(fis,ruleList)
```

## Description

`addrule` has two arguments. The first argument is the MATLAB® workspace variable FIS name. The second argument is a matrix of one or more rows, each of which represents a given rule. The format that the rule list matrix must take is very specific. If there are m inputs to a system and n outputs, there must be exactly m + n + 2 columns to the rule list.

The first m columns refer to the inputs of the system, and the next n columns refer to the outputs of the system. Each column contains a number that refers to the index of the membership function for that variable. To indicate a NOT condition for an input or output variable, use a negative number. To indicate a don’t care condition, use a `0`.

The m + n + 1 column contains the weight that is to be applied to the rule. The weight must be a number between zero and one and is generally left as one.

The m + n + 2 column contains a 1 if the fuzzy operator for the rule's antecedent is AND. It contains a 2 if the fuzzy operator is OR.

For information on how to delete rules from an FIS, see Tips.

## Examples

collapse all

Create the fuzzy inference system. For this example, load the `tipper` FIS and clear the existing rules for the FIS.

```sys = readfis('tipper'); sys.rule = []; ```

Create a rule list.

```rule1 = [1 1 1 1 1]; rule2 = [1 2 2 1 1]; ruleList = [rule1;rule2]; ```

Add the rule list to the FIS.

```sys = addrule(sys,ruleList); ```

Verify that the rules were added.

```showrule(sys) ```
```ans = 2x73 char array '1. If (service is poor) and (food is rancid) then (tip is cheap) (1) ' '2. If (service is poor) and (food is delicious) then (tip is average) (1)' ```

## Tips

• To delete a rule from an FIS, set the corresponding element of the rule list to an empty matrix, `[]`. For example, load the `tipper` FIS and view the existing rule list.

```sys = readfis('tipper'); showrule(sys) ```
```ans = 3x78 char array '1. If (service is poor) or (food is rancid) then (tip is cheap) (1) ' '2. If (service is good) then (tip is average) (1) ' '3. If (service is excellent) or (food is delicious) then (tip is generous) (1)' ```

Delete the second rule by setting it to `[]`.

```sys.rule(2) = []; ```

Verify that the rule was deleted.

```showrule(sys) ```
```ans = 2x78 char array '1. If (service is poor) or (food is rancid) then (tip is cheap) (1) ' '2. If (service is excellent) or (food is delicious) then (tip is generous) (1)' ```
• To delete all rules from an FIS, set the rule list to an empty matrix. For example:

```sys.rule = []; ```