📄 smf.m
字号:
function y = smf(x, params)
%SMF S-shaped curve membership function.
% SMF(X, PARAMS) returns a matrix which is the S-shaped
% membership function evaluated at X. PARAMS = [X0 X1] is a 2-element
% vector that determines the break points of this membership function.
% When X0 < X1, SMF is a smooth transition from 0 (at X0) to 1 (at X1).
% When X0 >= X1, SMF becomes a step function which jumps from 0 to 1
% at (X0+X1)/2.
%
% For example:
%
% x = 0:0.1:10;
% subplot(311); plot(x, smf(x, [2 8]));
% subplot(312); plot(x, smf(x, [4 6]));
% subplot(313); plot(x, smf(x, [6 4]));
% set(gcf, 'name', 'smf', 'numbertitle', 'off');
%
% See also
% dsigmf, gauss2mf, gaussmf, gbellmf, evalmf, pimf, psigmf,
% sigmf, trapmf, trimf, zmf, mf2mf
% Roger Jang, 10-5-93, 7-14-94.
% Copyright (c) 1994-98 by The MathWorks, Inc.
% $Revision: 1.16 $ $Date: 1997/12/01 21:45:26 $
if nargin ~= 2,
error('Two arguments are required by SMF.');
elseif length(params) < 2,
error('SMF needs at least two parameters.');
end
x0 = params(1); x1 = params(2);
if x0 >= x1,
y = x >= (x0+x1)/2;
return;
end
y = zeros(size(x));
index1 = find(x <= x0);
if ~isempty(index1),
y(index1) = zeros(size(index1));
end
index2 = find((x0 < x) & (x <= (x0+x1)/2));
if ~isempty(index2),
y(index2) = 2*((x(index2)-x0)/(x1-x0)).^2;
end
index3 = find(((x0+x1)/2 < x) & (x <= x1));
if ~isempty(index3),
y(index3) = 1-2*((x1-x(index3))/(x1-x0)).^2;
end
index4 = find(x1 <= x);
if ~isempty(index4),
y(index4) = ones(size(index4));
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -