title: Error in inference system in fuzzy Logic - R
body: <p>I am trying to implement a fuzzy inference system in R using frbs package.
  Here is my code -</p>
  
  <pre><code>varinp.mf &lt;- matrix(c(1,1,1,1,3,1,1,4,3,1,1,1,1,3,1,4,4,3,
                    0,20,40,70,85,0,5,30,65,0,25,40,70,85,0,20,45,70,
                    15,35,65,85,95,5,25,45,90,20,30,50,75,95,15,30,50,90,
                    30,45,75,90,0,10,35,65,90,30,45,75,90,100,25,40,65,100,
                    0,0,0,0,0,0,0,75,100,0,0,0,0,0,0,50,75,0
   ), nrow=5, byrow=TRUE)
  
   ## Define number of linguistic terms of input variables.
  num.fvalinput &lt;- matrix(c(5, 4, 5, 4), nrow=1)
  
  varinput.1 &lt;- c("veryPoor", "Poor", "Average","Good","veryGood")
  varinput.2 &lt;- c("Less", "Average", "Many", "aLot")
  varinput.3 &lt;- c("veryPoor", "Poor", "Average","Good","veryGood")
  varinput.4 &lt;- c("Less", "Average", "More","High")
  names.varinput &lt;- c(varinput.1, varinput.2, varinput.3, varinput.4)
  
  ## Set interval of data.
  range.data &lt;- matrix(c(0, 100, 0, 100, 0, 100, 0, 100, 0, 100), nrow = 2)
  
   ## Define inference parameters.
   ## Detailed information about values can be seen in the inference function.
  type.defuz &lt;- "WAM"
  type.tnorm &lt;- "MIN"
  type.snorm &lt;- "MAX"
  type.implication.func &lt;- "ZADEH"
  
  ## Give the name of simulation.
  name &lt;- "Sim-0"
  
  ## the names of variables
  colnames.var &lt;- c("Hotel_Facility_Score", "Visited_Count", "Room_facility_score", "Average_price", "Relative_Class")
  
  ## Define number of linguistic terms of output variable.
  ## In this case, we set the number of linguistic terms to 3.
  num.fvaloutput &lt;- matrix(c(5), nrow = 1)
  
  ## Give the names of the linguistic terms of the output variable.
  varoutput.1 &lt;- c("veryGood", "Good", "Average","Poor","veryPoor")
  names.varoutput &lt;- c(varoutput.1)
  
  
  ## Define the shapes and parameters of the membership functions of the output variables.
  varout.mf &lt;- matrix(c(5,5,5,5,5,
                    95,75,55,35,20,
                    4,8,5,7,5,
                    0,0,0,0,0,
                    0,0,0,0,0),
                  nrow = 5, byrow = TRUE)
  
  ## Define the fuzzy IF-THEN rules;
  
  rule &lt;- matrix(
   c("veryGood", "and", "aLot", "and", "veryGood", "and", "less", "-&gt;", "veryGood",
  "veryGood", "and", "Many", "and", "veryGood", "and", "Average", "-&gt;", "veryGood",
  "veryGood", "and", "aLot", "and", "veryGood", "and", "Average", "-&gt;", "Good",
  "veryGood", "and", "aLot", "and", "veryGood", "and", "Less", "-&gt;", "Good",
  "Good", "and", "Many", "and", "Good", "and", "Less", "-&gt;", "Good",
  "Good", "and", "aLot", "and", "Good", "and", "Average", "-&gt;", "Good",
  "Average", "and", "aLot", "and", "Good", "and", "Less", "-&gt;", "Average",
  "veryGood", "and", "Average", "and", "veryGood", "and", "More", "-&gt;", "Average",
  "Good", "and", "Many", "and", "Good", "and", "Average", "-&gt;", "Average",
  "Average", "and", "Average", "and", "Average", "and", "More", "-&gt;", "Poor",
  "Good", "and", "Many", "and", "vGood", "and", "High", "-&gt;", "Poor",
  "Average", "and", "Average", "and", "Average", "and", "High", "-&gt;", "Poor",
  "Poor", "and", "Less", "and", "Poor","and", "High", "-&gt;", "veryPoor",
  "veryPoor", "and", "Less", "and", "veryPoor", "and", "High", "-&gt;", "veryPoor"),
    nrow = 14, byrow = TRUE)
  
  ## Set type of model which is "MAMDANI".
  type.model &lt;- "MAMDANI"
  
  
  
  ## Generate a fuzzy model with frbs.gen.
  object &lt;- frbs.gen(range.data, num.fvalinput, names.varinput,
                 num.fvaloutput, varout.mf, names.varoutput, rule,
                 varinp.mf, type.model, type.defuz, type.tnorm,
                 type.snorm, func.tsk = NULL, colnames.var, type.implication.func, name)
  
  ## Plot the membership function.
  plotMF(object)
  
  
  newdata &lt;- matrix(c(15, 80, 85, 85, 45, 75, 78, 70), nrow = 2, byrow = TRUE)
  
  ## Fuzzification Module:
  
  num.varinput &lt;- ncol(num.fvalinput)
  MF &lt;- fuzzifier(newdata, num.varinput, num.fvalinput, varinp.mf)
  
  
  ## Check input data given by user.
  ruleb &lt;- rulebase(type.model, rule, func.tsk = NULL)
  
  
  ## Inference Module:
  miu.rule &lt;- inference(MF, ruleb, names.varinput, type.tnorm, type.snorm)
  </code></pre>
  
  <p>I am getting this error - </p>
  
  <blockquote>
    <p>miu.rule &lt;- inference(MF, ruleb, names.varinput, type.tnorm, type.snorm)</p>
    
    <p>Error in MF[k, temp[j + 2]] : subscript out of bounds</p>
  </blockquote>
  
  <p>I took help from the example give at this link -
  <a href="http://www.inside-r.org/packages/cran/frbs/docs/frbs.gen" rel="nofollow">http://www.inside-r.org/packages/cran/frbs/docs/frbs.gen</a></p>
  
  <p>But the example runs fine. I am not able to find what is the error in my code.</p>