have a issue with scalar
7 ビュー (過去 30 日間)
古いコメントを表示
Reen Blake-Carr
2020 年 8 月 10 日
回答済み: Sarvani Panguluri
2020 年 8 月 13 日
i am having a issue with the plot mf function within creating my fuzzy ifnerence system when trying to plot the mf using the graph function i recieve the error expected input index to be scalar with value <=2 and or <=1 this can be seen below in my code generation
> fis = mamfis('Name', "Diabetes");
fis = addInput(fis,[0 30], 'Name',"Glucose");
fis = addmf(fis,"Glucose","trimf",[0 5 10],'Name',"low");
fis = addmf(fis,"Glucose","trimf",[10 15 20],'Name',"medium");
fis = addmf(fis,"Glucose","trimf",[20 25 30],'Name',"High");
fis = addInput(fis,[0 30],'Name',"BMI");
fis = addmf(fis,"BMI","trimf",[0 5 10],'Name',"low");
fis = addmf(fis,"BMI","trimf",[10 15 20],'Name',"medium");
fis = addmf(fis,"BMI","trimf",[20 25 30],'Name',"High");
fis = addOutput(fis,[0 1],'Name',"Diabetes");
fis = addmf(fis,"Diabetes","trimf",[0 0.2 0.4],'Name',"NoDiabetes");
fis = addmf(fis,"Diabetes","trimf",[0.5 0.6 0.7],'Name',"HasDiabetes");
RuleList = [1 2 1 1 1;
2 1 1 1 1;
3 3 2 1 1;
]
fis = addRule(fis,RuleList)
RuleList =
1 2 1 1 1
2 1 1 1 1
3 3 2 1 1
fis =
mamfis with properties:
Name: "Diabetes"
AndMethod: "min"
OrMethod: "max"
ImplicationMethod: "min"
AggregationMethod: "max"
DefuzzificationMethod: "centroid"
Inputs: [1×2 fisvar]
Outputs: [1×1 fisvar]
Rules: [1×3 fisrule]
DisableStructuralChecks: 0
See 'getTunableSettings' method for parameter optimization.
>> plotmf(fis,'input',1)
>> plotmf(fis,'input',2)
>> plotmf(fis,'input',3)
Error using plotmf (line 52)
Expected input index to be a scalar with value <= 2.
>> plotmf(fis,'output',2)
Error using plotmf (line 52)
Expected output index to be a scalar with value <= 1.
And when i use the code that the error generates i am not sure what to correct as i am very new to using MATLAB and gogoling the errors didnt seem to work
function varargout = plotmf(fis,varType,varIndex,numPts)
%PLOTMF Display all of the membership functions for a given variable.
% PLOTMF(fismat,varType,varIndex) plots all of the membership functions
% in the FIS called fismat associated with a given variable whose type
% (input or output) and index are respectively given by varType and
% varIndex. This function can also be used with the MATLAB function
% subplot.
%
% [xOut,yOut] = PLOTMF(fismat,varType,varIndex) returns the x and y data
% points associated with the membership functions without plotting them.
%
% [xOut,yOutUpper,yOutLower] = PLOTMF(fismat,varType,varIndex) returns
% the x and y data points associated with the upper and lower membership
% functions of a type-2 FIS called fismat without plotting them.
%
% PLOTMF(fismat,varType,varIndex,numPts) generates the same plot with
% exactly numPts points plotted along the curve.
%
% The varType input argument is specified by a character row vector or
% string scalar.
%
% For example:
%
% fis = mamfis;
% fis = addInput(fis,[0 10],'Name','service');
% fis = addMF(fis,'service','gaussmf',[1.5 0],'Name','poor');
% fis = addMF(fis,'service','gaussmf',[1.5 5],'Name','good');
% fis = addMF(fis,'service','gaussmf',[1.5 10],'Name','excellent');
% plotmf(fis,'input',1)
%
% See also EVALMF, PLOTFIS.
% Copyright 1994-2019 The MathWorks, Inc.
%====================================
narginchk(3,4)
fuzzy.internal.utility.validateFIS(fis)
if ~isa(fis,'FuzzyInferenceSystem')
warning(message('fuzzy:general:warnDeprecation_FISStructure'))
fis = convertfis(fis);
end
fuzzy.internal.utility.validCharOrString('Variable type',varType);
if varType~="input" && varType~="output"
error(message('fuzzy:general:errVariable_InvalidType'));
end
if varType=="output" && fis.type=="sugeno"
error(message('fuzzy:general:errPlotmf_SugenoOutputMF'));
end
validateattributes(...
varIndex, ...
{'numeric'}, ...
{'nonempty','scalar','real','positive','integer', ...
'<=',length(fis.(varType))}, ...
'', ...
[char(varType) ' index'] ...
)
if nargin<4
numPts = 181;
else
validateattributes(...
numPts, ...
{'numeric'}, ...
{'nonempty','scalar','real','finite','integer','>',1}, ...
'', ...
['number of points taken in ' char(varType) ' range'] ...
)
end
var = fis.(varType)(varIndex);
numMFs = length(var.mf);
if numMFs == 0
error(message("fuzzy:general:errFIS_MissingMFs",varType))
end
x = linspace(var.range(1),var.range(2),numPts)';
if nargout<1
plot(var.mf,x,'XLabel',var.Name)
else
varargout{1} = x(:,ones(numMFs,1));
if nargout > 1
[varargout{2:nargout}] = getMembershipValue(var.mf,x);
if numMFs > 1
for i = 2:nargout
varargout{i} = varargout{i}';
end
end
end
end
if anyone can help it would be much appreciated.
0 件のコメント
採用された回答
Sarvani Panguluri
2020 年 8 月 13 日
Hi,
I assume you are trying to use the plotmf function in your fuzzy inference system.From the mamfis properties of your code,it is observed that there are 2 inputs(Glucose and BMI i suppose) and 1 output(Diabetes).
plotmf(fis,variableType,variableIndex)
In the plotmf function ,depending on the variableType(which is input or output), it is expected that variableIndex should be less than or equal to the number of input /output variables in fis.
plotmf(fis,'input',3)
plotmf(fis,'output',2)
In your code , since there are only 2 inputs and 1 output ,using the above lines throws an error.Please refer to the following documentation for more insight.
Hope this helps!
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Fuzzy Inference System Modeling についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!