You are on page 1of 18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

BuildMamdaniSystems(GUI)
Onthispage

HowtoBuildMamdaniSystemsUsingFuzzyLogicToolboxGraphicalUserInterfaceTools
TheBasicTippingProblem
TheFuzzyLogicDesigner
TheMembershipFunctionEditor
TheRuleEditor
TheRuleViewer
TheSurfaceViewer
ImportingandExportingfromtheGUITools

HowtoBuildMamdaniSystemsUsingFuzzyLogicToolboxGraphicalUserInterfaceTools
ThisexampleshowshowtobuildaFuzzyInferenceSystem(FIS)forthetippingexample,describedinThe
BasicTippingProblem,usingtheFuzzyLogicToolboxgraphicaluserinterface(GUI)tools.
Youusethefollowinggraphicaltoolstobuild,edit,andviewfuzzyinferencesystems:
FuzzyLogicDesignertohandlethehighlevelissuesforthesystemHowmanyinputandoutput
variables?Whataretheirnames?
FuzzyLogicToolboxsoftwaredoesnotlimitthenumberofinputs.However,thenumberofinputsmay
belimitedbytheavailablememoryofyourmachine.Ifthenumberofinputsistoolarge,orthenumberof
membershipfunctionsistoobig,thenitmayalsobedifficulttoanalyzetheFISusingtheothertools.
MembershipFunctionEditortodefinetheshapesofallthemembershipfunctionsassociatedwith
eachvariable
RuleEditortoeditthelistofrulesthatdefinesthebehaviorofthesystem.
RuleViewertoviewthefuzzyinferencediagram.Usethisviewerasadiagnostictosee,forexample,
whichrulesareactive,orhowindividualmembershipfunctionshapesinfluencetheresults
SurfaceViewertoviewthedependencyofoneoftheoutputsonanyoneortwooftheinputsthatis,it
generatesandplotsanoutputsurfacemapforthesystem.
TheseGUIsaredynamicallylinked,inthatchangesyoumaketotheFISusingoneofthem,affectwhatyou
seeonanyoftheotheropenGUIs.Forexample,ifyouchangethenamesofthemembershipfunctionsin
theMembershipFunctionEditor,thechangesarereflectedintherulesshownintheRuleEditor.Youcan
usetheGUIstoreadandwritevariablesbothtotheMATLABworkspaceandtoafile(thereadonly
viewerscanstillexchangeplotswiththeworkspaceandsavethemtoafile).Youcanhaveanyorallof
themopenforanygivensystemorhavemultipleeditorsopenforanynumberofFISsystems.

http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

1/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

ThefollowingfigureshowshowthemaincomponentsofaFISandthethreeeditorsfittogether.Thetwo
viewersexaminethebehavioroftheentiresystem.

InadditiontothesefiveprimaryGUIs,thetoolboxincludesthegraphicalNeuroFuzzyDesigner,whichyou
usetobuildandanalyzeSugenotypeadaptiveneurofuzzyinferencesystems.
TheFuzzyLogicToolboxGUIsdonotsupportbuildingFISusingdata.Ifyouwanttousedatatobuilda
FIS,useoneofthefollowingtechniques:
genfis1,genfis2,orgenfis3commandstogenerateaSugenotypeFIS.Then,selectFile>Importin

theFuzzyLogicDesignertoimporttheFISandperformfuzzyinference,asdescribedinTheFuzzy
LogicDesigner.
NeuroadaptivelearningtechniquestomodeltheFIS,asdescribedinanfisandtheNeuroFuzzy
Designer.
IfyouwantouseMATLABworkspacevariables,usethecommandlineinterfaceinsteadoftheFuzzyLogic
http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

2/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

Designer.Foranexample,seeBuildingaSystemfromScratch.

TheBasicTippingProblem
Thisexampleusesatwoinput,oneoutputtippingproblembasedontippingpracticesintheU.S.
Givenanumberbetween0and10thatrepresentsthequalityofserviceatarestaurant(where10is
excellent),andanothernumberbetween0and10thatrepresentsthequalityofthefoodatthatrestaurant
(again,10isexcellent),whatshouldthetipbe?
Thestartingpointistowritedownthethreegoldenrulesoftipping:
1. Iftheserviceispoororthefoodisrancid,thentipischeap.
2. Iftheserviceisgood,thentipisaverage.
3. Iftheserviceisexcellentorthefoodisdelicious,thentipisgenerous.
Assumethatanaveragetipis15%,ageneroustipis25%,andacheaptipis5%.

Obviouslythenumbersandtheshapeofthecurvearesubjecttolocaltraditions,culturalbias,andsoon,but
thethreerulesaregenerallyuniversal.
Nowthatyouknowtherulesandhaveanideaofwhattheoutputshouldlooklike,usetheGUItoolsto
constructafuzzyinferencesystemforthisdecisionprocess.

TheFuzzyLogicDesigner
TheFuzzyLogicDesignerdisplaysinformationaboutafuzzyinferencesystem.ToopentheFuzzyLogic
Designer,typethefollowingcommandattheMATLABprompt:

fuzzyLogicDesigner
TheFuzzyLogicDesigneropensanddisplaysadiagramofthefuzzyinferencesystemwiththenamesof
eachinputvariableontheleft,andthoseofeachoutputvariableontheright,asshowninthenextfigure.
Thesamplemembershipfunctionsshownintheboxesarejusticonsanddonotdepicttheactualshapesof
themembershipfunctions.

http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

3/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

Belowthediagramisthenameofthesystemandthetypeofinferenceused.

Inthisexample,youusethedefaultMamdanitypeinference.Anothertypeofinference,calledSugenotype
inference,isalsoavailable.SeeWhatIsSugenoTypeFuzzyInference?.
IntheFuzzyLogicDesigner:
Thedropdownlistsletyoumodifythefuzzyinferencefunctions.
TheCurrentVariableareadisplaysthenameofeitheraninputoroutputvariable,itstype,anddefault
range.
Astatuslineatthebottomdisplaysinformationaboutthemostrecentoperation.
TobuildtheFuzzyInferenceSystemdescribedinTheBasicTippingProblemfromscratch,typethe
followingcommandattheMATLABprompt:
http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

4/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

fuzzyLogicDesigner
ThegenericuntitledFuzzyLogicDesigneropens,withoneinputinput1,andoneoutputoutput1.

TipToopentheFuzzyLogicDesignerwiththeprebuiltfuzzyinferencesystemstoredintipper.fis,
type

fuzzyLogicDesignertipper
However,ifyouloadtheprebuiltsystem,youwillnotbuildrulesorconstructmembershipfunctions.

Inthisexample,youconstructatwoinput,oneoutputsystem.Thetwoinputsareserviceandfood.The
oneoutputistip.
Toaddasecondinputvariableandchangethevariablenamestoreflectthesedesignations:
1. SelectEdit>Addvariable>Input.
Asecondyellowboxlabeledinput2appears.
2. Clicktheyellowboxinput1.Thisboxishighlightedwitharedoutline.
3. EdittheNamefieldfrominput1toservice,andpressEnter.
4. Clicktheyellowboxinput2.Thisboxishighlightedwitharedoutline.
5. EdittheNamefieldfrominput2tofood,andpressEnter.
6. Clicktheblueboxoutput1.
http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

5/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

7. EdittheNamefieldfromoutput1totip,andpressEnter.
8. SelectFile>Export>ToWorkspace.

9. EntertheWorkspacevariablenametipper,andclickOK.
Thediagramisupdatedtoreflectthenewnamesoftheinputandoutputvariables.Thereisnowanew
variableintheworkspacecalledtipperthatcontainsalltheinformationaboutthissystem.Bysavingto
theworkspacewithanewname,youalsorenametheentiresystem.Yourwindowlookssomethinglike
thefollowingdiagram.

Leavetheinferenceoptionsinthelowerleftintheirdefaultpositionsfornow.Youhaveenteredallthe
informationyouneedforthisparticularGUI.Next,definethemembershipfunctionsassociatedwitheachof
thevariables.Todothis,opentheMembershipFunctionEditor.
YoucanopentheMembershipFunctionEditorinoneofthreeways:

http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

6/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

WithintheFuzzyLogicDesignerwindow,selectEdit>MembershipFunctions..
WithintheFuzzyLogicDesignerwindow,doubleclicktheblueiconcalledtip.
Atthecommandline,typemfedit.

TheMembershipFunctionEditor
TheMembershipFunctionEditoristhetoolthatletsyoudisplayandeditallofthemembershipfunctions
associatedwithalloftheinputandoutputvariablesfortheentirefuzzyinferencesystem.TheMembership
FunctionEditorsharessomefeatureswiththeFuzzyLogicDesigner,asshowninthenextfigure.Infact,all
ofthefivebasicGUItoolshavesimilarmenuoptions,statuslines,andHelpandClosebuttons.

WhenyouopentheMembershipFunctionEditortoworkonafuzzyinferencesystemthatdoesnotalready
existintheworkspace,therearenomembershipfunctionsassociatedwiththevariablesthatyoudefined
http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

7/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

withtheFuzzyLogicDesigner.
OntheupperleftsideofthegraphareaintheMembershipFunctionEditorisa"VariablePalette"thatlets
yousetthemembershipfunctionsforagivenvariable.
TosetupthemembershipfunctionsassociatedwithaninputoranoutputvariablefortheFIS,selectaFIS
variableinthisregionbyclickingit.
NextselecttheEditpulldownmenu,andchooseAddMFs..Anewwindowappears,whichallowsyouto
selectboththemembershipfunctiontypeandthenumberofmembershipfunctionsassociatedwiththe
selectedvariable.Inthelowerrightcornerofthewindowarethecontrolsthatletyouchangethename,type,
andparameters(shape),ofthemembershipfunction,afteritisselected.
Themembershipfunctionsfromthecurrentvariablearedisplayedinthemaingraph.Thesemembership
functionscanbemanipulatedintwoways.Youcanfirstusethemousetoselectaparticularmembership
functionassociatedwithagivenvariablequality,(suchaspoor,forthevariable,service),andthendragthe
membershipfunctionfromsidetoside.Thisactionaffectsthemathematicaldescriptionofthequality
associatedwiththatmembershipfunctionforagivenvariable.Theselectedmembershipfunctioncanalso
betaggedfordilationorcontractionbyclickingonthesmallsquaredragpointsonthemembershipfunction,
andthendraggingthefunctionwiththemousetowardtheoutside,fordilation,ortowardtheinside,for
contraction.Thisactionchangestheparametersassociatedwiththatmembershipfunction.
BelowtheVariablePaletteissomeinformationaboutthetypeandnameofthecurrentvariable.Thereisa
textfieldinthisregionthatletsyouchangethelimitsofthecurrentvariable'srange(universeofdiscourse)
andanotherthatletsyousetthelimitsofthecurrentplot(whichhasnorealeffectonthesystem).
Theprocessofspecifyingthemembershipfunctionsforthetwoinputtippingexample,tipper,isasfollows:
1. DoubleclicktheinputvariableservicetoopentheMembershipFunctionEditor.

http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

8/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

2. IntheMembershipFunctionEditor,enter[010]intheRangeandtheDisplayRangefields.
3. Createmembershipfunctionsfortheinputvariableservice.
a. SelectEdit>RemoveAllMFstoremovethedefaultmembershipfunctionsfortheinputvariable
service.
b. SelectEdit>AddMFs.toopentheMembershipFunctionsdialogbox.
c. IntheMembershipFunctionsdialogbox,selectgaussmfastheMFType.

d. Verifythat3isselectedastheNumberofMFs.
e. ClickOKtoaddthreeGaussiancurvestotheinputvariableservice.
4. Renamethemembershipfunctionsfortheinputvariableservice,andspecifytheirparameters.
a. Clickonthecurvenamedmf1toselectit,andspecifythefollowingfieldsintheCurrent
http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

9/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

MembershipFunction(clickonMFtoselect)area:
IntheNamefield,enterpoor.
IntheParamsfield,enter[1.50].
ThetwoinputsofParamsrepresentthestandarddeviationandcenterfortheGaussiancurve.
TipToadjusttheshapeofthemembershipfunction,typeinthedesiredparametersor
usethemouse,asdescribedpreviously.

b. Clickonthecurvenamedmf2toselectit,andspecifythefollowingfieldsintheCurrent
MembershipFunction(clickonMFtoselect)area:
IntheNamefield,entergood.
IntheParamsfield,enter[1.55].
c. Clickonthecurvenamedmf3,andspecifythefollowingfieldsintheCurrentMembership
Function(clickonMFtoselect)area:
IntheNamefield,enterexcellent.
IntheParamsfield,enter[1.510].
TheMembershipFunctionEditorwindowlookssimilartothefollowingfigure.

5. IntheFISVariablesarea,clicktheinputvariablefoodtoselectit.
http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

10/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

6. Enter[010]intheRangeandtheDisplayRangefields.
7. Createthemembershipfunctionsfortheinputvariablefood.
a. SelectEdit>RemoveAllMFstoremovethedefaultMembershipFunctionsfortheinputvariable
food.
b. SelectEdit>AddMFstoopentheMembershipFunctionsdialogbox.
c. IntheMembershipFunctionsdialogbox,selecttrapmfastheMFType.
d. Select2intheNumberofMFsdropdownlist.
e. ClickOKtoaddtwotrapezoidalcurvestotheinputvariablefood.
8. Renamethemembershipfunctionsfortheinputvariablefood,andspecifytheirparameters:
a. IntheFISVariablesarea,clicktheinputvariablefoodtoselectit.
b. Clickonthecurvenamedmf1,andspecifythefollowingfieldsintheCurrentMembership
Function(clickonMFtoselect)area:
IntheNamefield,enterrancid.
IntheParamsfield,enter[0013].
c. Clickonthecurvenamedmf2toselectit,andenterdeliciousintheNamefield.
Resettheassociatedparametersifdesired.
9. Clickontheoutputvariabletiptoselectit.
10. Enter[030]intheRangeandtheDisplayRangefieldstocovertheoutputrange.
Theinputsrangesfrom0to10,buttheoutputisatipbetween5%and25%.
11. Renamethedefaulttriangularmembershipfunctionsfortheoutputvariabletip,andspecifytheir
parameters.
a. Clickthecurvenamedmf1toselectit,andspecifythefollowingfieldsintheCurrentMembership
Function(clickonMFtoselect)area:
IntheNamefield,entercheap.
IntheParamsfield,enter[0510].
b. Clickthecurvenamedmf2toselectit,andspecifythefollowingfieldsintheCurrentMembership
Function(clickonMFtoselect)area:
IntheNamefield,enteraverage.
IntheParamsfield,enter[101520].
c. Clickthecurvenamedmf3toselectit,andspecifythefollowing:
IntheNamefield,entergenerous.
IntheParamsfield,enter[202530].
TheMembershipFunctionEditorlookssimilartothefollowingfigure.

http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

11/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

Nowthatthevariableshavebeennamedandthemembershipfunctionshaveappropriateshapesand
names,youcanentertherules.TocalluptheRuleEditor,gototheEditmenuandselectRules,ortype
ruleeditatthecommandline.

TheRuleEditor

http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

12/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

ConstructingrulesusingthegraphicalRuleEditorinterfaceisfairlyselfevident.Basedonthedescriptionsof
theinputandoutputvariablesdefinedwiththeFuzzyLogicDesigner,theRuleEditorallowsyoutoconstruct
therulestatementsautomatically,FromtheGUI,youcan:
Createrulesbyselectinganitemineachinputandoutputvariablebox,selectingoneConnectionitem,
andclickingAddRule.Youcanchoosenoneasoneofthevariablequalitiestoexcludethatvariable
fromagivenruleandchoosenotunderanyvariablenametonegatetheassociatedquality.
DeletearulebyselectingtheruleandclickingDeleteRule.
EditarulebychangingtheselectioninthevariableboxandclickingChangeRule.
Specifyweighttoarulebytypinginadesirednumberbetween0and1inWeight.Ifyoudonotspecify
theweight,itisassumedtobeunity(1).
SimilartothoseintheFuzzyLogicDesignerandtheMembershipFunctionEditor,theRuleEditorhasthe
menubarandthestatusline.Themenuitemsallowyoutoopen,close,saveandeditafuzzysystemusing
thefivebasicGUItools.Fromthemenu,youcanalso:
SettheformatforthedisplaybyselectingOptions>Format.
SetthelanguagebyselectingOptions>Language.
YoucanaccessinformationabouttheRuleEditorbyclickingHelpandclosetheGUIusingClose.
ToinsertthefirstruleintheRuleEditor,selectthefollowing:
poorunderthevariableservice
rancidunderthevariablefood

Theorradiobutton,intheConnectionblock
cheap,undertheoutputvariable,tip.

Then,clickAddrule.
Theresultingruleis
1.If(serviceispoor)or(foodisrancid)then(tipischeap)(1)

Thenumbersintheparenthesesrepresentweights.
FollowasimilarproceduretoinsertthesecondandthirdrulesintheRuleEditortoget
1. If(serviceispoor)or(foodisrancid)then(tipischeap)(1)
2. If(serviceisgood)then(tipisaverage)(1)
3. If(serviceisexcellent)or(foodisdelicious)then(tipisgenerous)(1)
TipTochangearule,firstclickontheruletobechanged.Nextmakethedesiredchangestothat
rule,andthenclickChangerule.Forexample,tochangethefirstruleto
1.If(servicenotpoor)or(foodnotrancid)then(tipisnotcheap)(1)

Selectthenotcheckboxundereachvariable,andthenclickChangerule.

TheFormatpopupmenufromtheOptionsmenuindicatesthatyouarelookingattheverboseformofthe
rules.Trychangingittosymbolic.Youwillsee
1.(service==poor)|(food==rancid)=>(tip=cheap)(1)
http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

13/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

2.(service==good)=>(tip=average)(1)
3.(service==excellent)|(food==delicious)=>(tip=generous)(1)

Thereisnotmuchdifferenceinthedisplayreally,butitisslightlymorelanguageneutral,becauseitdoesnot
dependontermslikeifandthen.Ifyouchangetheformattoindexed,youseeanextremelycompressed
versionoftherules.
11,1(1):2
20,2(1):1
32,3(1):2

Thisistheversionoftherulesthatthemachinedealswith.
Thefirstcolumninthisstructurecorrespondstotheinputvariables.
Thesecondcolumncorrespondstotheoutputvariable.
Thethirdcolumndisplaystheweightappliedtoeachrule.
ThefourthcolumnisshorthandthatindicateswhetherthisisanOR(2)ruleoranAND(1)rule.
Thenumbersinthefirsttwocolumnsrefertotheindexnumberofthemembershipfunction.
Aliteralinterpretationofrule1is"Ifinput1isMF1(thefirstmembershipfunctionassociatedwithinput1)or
ifinput2isMF1,thenoutput1shouldbeMF1(thefirstmembershipfunctionassociatedwithoutput1)with
theweight1.
Thesymbolicformatdoesnotconsidertheterms,if,then,andsoon.Theindexedformatdoesn'teven
botherwiththenamesofyourvariables.Obviouslythefunctionalityofyoursystemdoesn'tdependonhow
wellyouhavenamedyourvariablesandmembershipfunctions.Thewholepointofnamingvariables
descriptivelyis,asalways,makingthesystemeasierforyoutointerpret.Thus,unlessyouhavesome
specialpurposeinmind,itisprobablybeeasierforyoutocontinuewiththeverboseformat.
Atthispoint,thefuzzyinferencesystemhasbeencompletelydefined,inthatthevariables,membership
functions,andtherulesnecessarytocalculatetipsareinplace.Now,lookatthefuzzyinferencediagram
presentedattheendoftheprevioussectionandverifythateverythingisbehavingthewayyouthinkit
should.YoucanusetheRuleViewer,thenextoftheGUItoolswe'lllookat.FromtheViewmenu,select
Rules.

TheRuleViewer

http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

14/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

TheRuleViewerdisplaysaroadmapofthewholefuzzyinferenceprocess.Itisbasedonthefuzzy
inferencediagramdescribedintheprevioussection.Youseeasinglefigurewindowwith10plotsnestedin
it.Thethreeplotsacrossthetopofthefigurerepresenttheantecedentandconsequentofthefirstrule.Each
ruleisarowofplots,andeachcolumnisavariable.Therulenumbersaredisplayedontheleftofeachrow.
Youcanclickonarulenumbertoviewtheruleinthestatusline.
Thefirsttwocolumnsofplots(thesixyellowplots)showthemembershipfunctionsreferencedbythe
antecedent,ortheifpartofeachrule.
Thethirdcolumnofplots(thethreeblueplots)showsthemembershipfunctionsreferencedbythe
consequent,orthethenpartofeachrule.
Noticethatunderfood,thereisaplotwhichisblank.Thiscorrespondstothecharacterizationofnone
forthevariablefoodinthesecondrule.
Thefourthplotinthethirdcolumnofplotsrepresentstheaggregateweighteddecisionforthegiven
inferencesystem.
Thisdecisionwilldependontheinputvaluesforthesystem.Thedefuzzifiedoutputisdisplayedasa
boldverticallineonthisplot.
Thevariablesandtheircurrentvaluesaredisplayedontopofthecolumns.Inthelowerleft,thereisatext
fieldInputinwhichyoucanenterspecificinputvalues.Forthetwoinputsystem,youwillenteraninput
vector,[98],forexample,andthenpressEnter.Youcanalsoadjusttheseinputvaluesbyclickingonany
ofthethreeplotsforeachinput.Thiswillmovetheredindexlinehorizontally,tothepointwhereyouhave
http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

15/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

clicked.Alternatively,youcanalsoclickanddragthislineinordertochangetheinputvalues.Whenyou
releasetheline,(oraftermanuallyspecifyingtheinput),anewcalculationisperformed,andyoucanseethe
wholefuzzyinferenceprocesstakeplace:
Wheretheindexlinerepresentingservicecrossesthemembershipfunctionline"serviceispoor"inthe
upperleftplotdeterminesthedegreetowhichruleoneisactivated.
Ayellowpatchofcolorundertheactualmembershipfunctioncurveisusedtomakethefuzzy
membershipvaluevisuallyapparent.
Eachofthecharacterizationsofeachofthevariablesisspecifiedwithrespecttotheinputindexlineinthis
manner.Ifyoufollowrule1acrossthetopofthediagram,youcanseetheconsequent"tipischeap"has
beentruncatedtoexactlythesamedegreeasthe(composite)antecedentthisistheimplicationprocessin
action.Theaggregationoccursdownthethirdcolumn,andtheresultantaggregateplotisshowninthesingle
plotappearinginthelowerrightcorneroftheplotfield.Thedefuzzifiedoutputvalueisshownbythethick
linepassingthroughtheaggregatefuzzyset.
Youcanshifttheplotsusingleft,right,down,andup.Themenuitemsallowyoutosave,open,oredita
fuzzysystemusinganyofthefivebasicGUItools.
TheRuleViewerallowsyoutointerprettheentirefuzzyinferenceprocessatonce.TheRuleVieweralso
showshowtheshapeofcertainmembershipfunctionsinfluencestheoverallresult.Becauseitplotsevery
partofeveryrule,itcanbecomeunwieldyforparticularlylargesystems,but,forarelativelysmallnumberof
inputsandoutputs,itperformswell(dependingonhowmuchscreenspaceyoudevotetoit)withupto30
rulesandasmanyas6or7variables.
TheRuleViewershowsonecalculationatatimeandingreatdetail.Inthissense,itpresentsasortofmicro
viewofthefuzzyinferencesystem.Ifyouwanttoseetheentireoutputsurfaceofyoursystemtheentire
spanoftheoutputsetbasedontheentirespanoftheinputsetyouneedtoopenuptheSurfaceViewer.
ThisvieweristhelastofthefivebasicFuzzyLogicToolboxGUItools.ToopentheSurfaceViewer,select
SurfacefromtheViewmenu.

TheSurfaceViewer

http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

16/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

UponopeningtheSurfaceViewer,youseeathreedimensionalcurvethatrepresentsthemappingfromfood
andservicequalitytotipamount.Becausethiscurverepresentsatwoinputoneoutputcase,youcansee
theentiremappinginoneplot.Whenwemovebeyondthreedimensionsoverall,westarttoencounter
troubledisplayingtheresults.
Accordingly,theSurfaceViewerisequippedwithdropdownmenusX(input):,Y(input):andZ(output):
thatletyouselectanytwoinputsandanyoneoutputforplotting.BelowthesemenusaretwoinputfieldsX
grids:andYgrids:thatletyouspecifyhowmanyxaxisandyaxisgridlinesyouwanttoinclude.This
capabilityallowsyoutokeepthecalculationtimereasonableforcomplexproblems.
Ifyouwanttocreateasmootherplot,usethePlotpointsfieldtospecifythenumberofpointsonwhichthe
membershipfunctionsareevaluatedintheinputoroutputrange.Bydefault,thevalueofthisfieldis101.
ClickingEvaluateinitiatesthecalculation,andtheplotisgeneratedafterthecalculationiscomplete.To
changethexaxisoryaxisgridafterthesurfaceisinview,changetheappropriateinputfield,andpress
Enter.Thesurfaceplotisupdatedtoreflectthenewgridsettings.
TheSurfaceViewerhasaspecialcapabilitythatisveryhelpfulincaseswithtwo(ormore)inputsandone
output:youcangrabtheaxes,usingthemouseandrepositionthemtogetadifferentthreedimensionalview
onthedata.
TheRef.Inputfieldisusedinsituationswhentherearemoreinputsrequiredbythesystemthanthesurface
ismapping.Youcaneditthisfieldtoexplicitlysetinputsnotspecifiedinthesurfaceplot.
Supposeyouhaveafourinputoneoutputsystemandwouldliketoseetheoutputsurface.TheSurface
Viewercangenerateathreedimensionaloutputsurfacewhereanytwooftheinputsvary,buttwoofthe
http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

17/18

2/5/2015

BuildMamdaniSystems(GUI)MATLAB&Simulink

inputsmustbeheldconstantbecausecomputermonitorscannotdisplayafivedimensionalshape.Insucha
case,theinputisafourdimensionalvectorwithNaNsholdingtheplaceofthevaryinginputswhilenumerical
valuesindicatesthosevaluesthatremainfixed.ANaNistheIEEEsymbolforNotaNumber.
Themenuitemsallowyoutoopen,close,saveandeditafuzzysystemusingthefivebasicGUItools.You
canaccessinformationabouttheSurfaceViewerbyclickingHelpandclosetheGUIusingClose.
ThisconcludesthequickwalkthroughofeachofthemainGUItools.Forthetippingproblem,theoutputof
thefuzzysystemmatchesyouroriginalideaoftheshapeofthefuzzymappingfromservicetotipfairlywell.
Inhindsight,youmightsay,"Whybother?Icouldhavejustdrawnaquicklookuptableandbeendonean
hourago!"However,ifyouareinterestedinsolvinganentireclassofsimilardecisionmakingproblems,
fuzzylogicmayprovideanappropriatetoolforthesolution,givenitseasewithwhichasystemcanbe
quicklymodified.

ImportingandExportingfromtheGUITools
Whenyousaveafuzzysystemtoafile,youaresavinganASCIItextFISfilerepresentationofthatsystem
withthefilesuffix.fis.Thistextfilecanbeeditedandmodifiedandissimpletounderstand.Whenyou
saveyourfuzzysystemtotheMATLABworkspace,youarecreatingavariable(whosenameyouchoose)
thatactsasaMATLABstructurefortheFISsystem.FISfilesandFISstructuresrepresentthesame
system.
NoteIfyoudonotsaveyourFIStoafile,butonlysaveittotheMATLABworkspace,youcannot
recoveritforuseinanewMATLABsession.

http://www.mathworks.com/help/fuzzy/buildingsystemswithfuzzylogictoolboxsoftware.html

18/18

You might also like