parsrule
(Removed) Parse fuzzy rules
parsrule
has been removed. Use addRule
instead.
For more information, see Version History.
Description
parses the rules in outFIS
= parsrule(inFIS
,ruleList
,Name,Value
)ruleList
using options specified by one or more
Name,Value
pair arguments.
Examples
Add Rules to Fuzzy Inference System
Load a fuzzy inference system (FIS).
fis = readfis('tipper');
Specify if-then rules using the default 'verbose'
format.
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 = parsrule(fis,rules);
fis2
is equivalent to fis
, except that the
rule base is replaced with the specified rules.
Add Rules Using Symbolic Expressions
Load a fuzzy inference system (FIS).
fis = readfis('tipper');
Specify the following rules using symbols:
If
service
ispoor
orfood
israncid
thentip
ischeap
.If
service
isexcellent
andfood
is notrancid
thentip
isgenerous
.
rule1 = "service==poor | food==rancid => tip=cheap"; rule2 = "service==excellent & food~=rancid => tip=generous"; rules = [rule1 rule2];
Add the rules to the FIS using the 'symbolic'
format.
fis2 = parsrule(fis,rules,'Format','symbolic');
Add Rules Using Membership Function Indices
Load fuzzy inference system (FIS).
fis = readfis('mam22.fis');
Specify the following rules using membership function indices:
If
angle
issmall
andvelocity
isbig
, thenforce
isnegBig
andforce2
isposBig2
.If
angle
is notsmall
andvelocity
issmall
, thenforce
isposSmall
andforce2
isnegSmall2
.
rule1 = "1 2, 1 4 (1) : 1"; rule2 = "-1 1, 3 2 (1) : 1"; rules = [rule1 rule2];
Add rules to FIS using the 'indexed'
format.
fis2 = parsrule(fis,rules,'Format','indexed');
Add Rules Using French Language
Load a fuzzy inference system (FIS).
fis = readfis('tipper');
Specify if-then rules using French keywords.
rule1 = "Si service est poor ou food est rancid alors tip est cheap"; rule2 = "Si service est excellent et food n''est_pas rancid alors tip est generous"; rules = [rule1 rule2];
Add the rules to the FIS.
fis2 = parsrule(fis,rules,'Language','francais');
Add Single Rule to Fuzzy Inference System
Load a fuzzy inference system (FIS).
a = readfis('tipper');
Add a rule to the FIS.
ruleTxt = 'If service is poor then tip is cheap'; a2 = parsrule(a,ruleTxt,'verbose');
Input Arguments
inFIS
— Fuzzy inference system
FIS structure
Input fuzzy inference system, specified as a FIS structure.
parsrule
does not modify inFIS
.
ruleList
— Fuzzy rules
character array | string array | character vector | string
Fuzzy rules, specified as one of the following:
Character array where each row corresponds to a rule. For example:
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);
String array, where each element corresponds to a rule. For example:
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 vector or string to specify a single rule.
You can change the rule format and language using the Format
and Language
options.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'Format','symbolic'
sets the rule format to symbolic
expressions.
Format
— Rule format
'verbose'
(default) | 'symbolic'
| 'indexed'
Rule format, specified as the comma-separated pair consisting
'Format'
and one of the following:
'verbose'
— Use linguistic expressions.'If service is poor or food is rancid then tip is cheap 1'
Specify the rule weight at the end of the rule text. If you omit the weight, a default value of
1
is used.You can specify the rule language using the
Language
option.'symbolic'
— Use language-neutral symbolic expressions.'service==poor | food==rancid => tip=cheap 1'
Specify symbolic expressions using the following symbols.
Rule Component Symbol AND &
OR |
IS (in antecedent) ==
IS (in consequent) =
IS NOT ~=
Implication (then) =>
Specify the rule weight at the end of the rule text. If you omit the weight, a default value of
1
is used.'indexed'
— Use input and output membership function (MF) indices.Specify indexed rules in the following format:
'<input MFs>, <output MFs>, (<weight>) : <logical operator - 1(AND), 2(OR)>'
For example:
'1 1, 1 (1) : 2'
To indicate NOT operations for input and output membership functions, use negative indices. For example, to specify "not the second membership function," use
-2
.To indicate a don’t care condition for an input or output membership function, use
0
.
Language
— Rule language
'english'
(default) | 'francais'
| 'deutsch'
Rule language for 'verbose'
format, specified as one of the
following:
'english'
— Specify rules in English.'If service is poor or food is rancid then tip is cheap'
'francais'
— Specify rules in French.'Si service est poor ou food est rancid alors tip est cheap'
'deutsch'
— Specify rules in German.'Wenn service ist poor oder food ist rancid dann tip ist cheap'
The software parses the rules in ruleList
using the following
keywords.
Rule Component | English | French | German |
---|---|---|---|
Start of antecedent | if | si | wenn |
AND | and | et | und |
OR | or | ou | oder |
Start of consequent (implication) | then | alors | dann |
IS | is | est | ist |
IS NOT | is not | n''est_pas | ist nicht |
Output Arguments
Version History
Introduced before R2006aR2024b: Removed
parsrule
has been removed. Use addRule
instead.
If you previously added rules using linguistic or symbolic expressions with
parsrule
, you can specify rules using the same expressions with
addrule
. addRule
automatically detects the
format of the strings or character vectors in your rule list. Therefore, it is no longer
necessary to specify the rule format. To add a rule list using addRule
,
use the following command:
fis = addRule(fis,rules);
Previously, you could add rules using indexed expressions with
parsrule
.
rule1 = "1 2, 1 4 (1) : 1"; rule2 = "-1 1, 3 2 (1) : 1"; rules = [rule1 rule2]; fis = parsrule(fis,rules,'Format','indexed');
Now, specify these rules using arrays of indices.
rule1 = [1 2 1 4 1 1]; rule2 = [-1 1 3 2 1 1]; rules = [rule1; rule2]; fis = addRule(fis,rules);
If you previously specified rules using the 'Language'
name-value
argument with parsrule
, this functionality has been removed and there
is no replacement. Specify your rules using addRule
with a different
rule format.
Previously, parsrule
replaced the entire rule list in your fuzzy
system. addRule
appends your specified rules to the rule list.
R2019b: Warns
parsrule
issues a warning that it will be removed in a future
release.
R2018b: To be removed
parsrule
runs without warning, but Code Analyzer indicates that
parsrule
will be removed in a future release.
R2017a: Specify options using name-value pair arguments
To specify options for creating new fuzzy inference systems, you now use name-value pair arguments. Any name-value pair arguments that you do not specify remain at their default values.
Previously, you specified options using optional input arguments
ruleFormat
and lang
.
outFIS = parsrule(inFIS,ruleList,ruleFormat,lang);
Starting in R2017a, modify your code to use one or more name-value pair arguments. For
example, add a list of rules in 'symbolic'
format.
fis = parsrule(inFIS,ruleList,'Format','symbolic');
The following table shows the mapping of the old input arguments to the new name-value pair arguments.
Old Input Argument | New Name-Value Argument |
---|---|
ruleFormat | 'Format' |
lang | 'Language' |
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)