readrule.m

来自「为了下载东西」· M 代码 · 共 46 行

M
46
字号
%
%  Syntax:  strRule = readrule(strBaseFile,RuleNr)
%
%  Inputs:  strBaseFile is the name of the text file containing the rule base.
%           Rule number RuleNr is to be read from the rulebase.
%
%  Result:  strRule is a textstring containing the RuleNr'th fuzzy rule in
%           the rule base, e.g. 'IF ISM AND MVL THEN SBH'.
%
%           Petur Snaeland,  30.04.1995.
%           Revised Hordur Kvaran, 20.10.97
%

function [strRule] = readrule(strBaseFile,RuleNr)

%
%  Open the text file containing the appropriate rule base.
%
[hBaseFile,errormessage] = fopen(strBaseFile,'rt+');
if (hBaseFile==-1),
   filepath=which(strBaseFile);
   if isempty(filepath),
      doevent('MainExit');
      error(strcat(strBaseFile,' not found in search path.')); 
   else hBaseFile = fopen(filepath,'rt+');
   end;
end;
%
%  Read the rules into one continuous string.
%
RuleBase = fscanf(hBaseFile,'%s');
%
%  Find and copy rule number RuleNr.
%
Rule = RuleBase((9*(RuleNr-1)+1):(9*(RuleNr-1)+9));
%
%  Add 'IF', 'AND' and 'THEN' to make the returned rule more readable.
%
strRule = [ 'IF ' Rule(1:3) ' AND ' Rule(4:6) ' THEN ' Rule(7:9) ];
%
%  Close the file and clear the temporary rulebase.
%
fclose(hBaseFile);
clear RuleBase;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?