function y = mfmf(x,params,option)
%MFMF M-shaped fuzzy curve membership function.
% MFMF(X, PARAMS, OPTION) returns a matrix which is the M-shaped
% membership function evaluated at X.
%
% PARAMS = PARAMS = [X0,X1,..,X4] or [X0,X1,..,X7]
% is a 5-element or an 8-element vector that determines the break points
% of this membership function.
% A more special case is the triggered Pulse-Membership Function
%
% OPTION = 1, 1.2, 1.3
% At n = 0 or 2;
% When Xn < Xn+1, MMF is a smooth transition from 0 (at Xn) to 1 (at Xn+1).
% else when Xn >= X(n+1),MMF becomes a step function
% jumping from 0 to 1 at (Xn+1+Xn)/2.
% At n = 1 or 3;
% When Xn < X(n+1), MMF is a smooth transition from 1 (at Xn) to 0 (at Xn+1).
% else when Xn >= X(n+1),MMF becomes a reverse-step function
%
% OPTION = 2, 2.2, 2.3
% At n = 0 or 4;
% When Xn < Xn+1, MMF is a smooth transition from 0 (at Xn) to 1 (at Xn+1).
% else when Xn >= X(n+1),MMF becomes a step function
% jumping from 0 to 1 at (Xn+1+Xn)/2.
% At n = 2 or 6;
% When Xn < X(n+1), MMF is a smooth transition from 1 (at Xn) to 0 (at Xn+1).
% else when Xn >= X(n+1),MMF becomes a reverse-step function
% jumping from 1 to 0 at (Xn+1+Xn)/2.
% At n = 1;
% MMF is a constant 1 (at Xn) to (at Xn+1).
% At n = 3;
% MMF is a constant 0 (at Xn) to (at Xn+1).
%
% For example:
% x = 0:0.1:10;
% mh =figure();
% %% type-1
% % We can write the letter M in 5!=120 different ways
% subplot(651); ax11 = plot(x, mfmf(x, [2.4 3 3.5 5.5 8]), '-.k');
% ax11.LineWidth = 1.5;
% grid on; grid minor;
% subplot(652); ax12 = plot(x, mfmf(x, [3 2 4 6 5]), '-.k');
% ax12.LineWidth = 1.5;
% grid on; grid minor;
% subplot(653); ax13 = plot(x, mfmf(x, [0 3 6 8 10]), '-.k');
% ax13.LineWidth = 1.5;
% grid on; grid minor;
% subplot(654); ax14 = plot(x, mfmf(x, [2 3 4 5 6]), '-.k');
% ax14.LineWidth = 1.5;
% grid on; grid minor;
% subplot(655); ax15 = plot(x, mfmf(x, [3 2 5 4 6]), '-.k');
% ax15.LineWidth = 1.5;
% grid on; grid minor;
% %% type-1.2
% % We can write the letter M in 5!=120 different ways
% subplot(656); ax21 = plot(x, mfmf(x, [2.4 3 3.5 5.5 8],1.2), '-.k');
% ax21.LineWidth = 1.5;
% grid on; grid minor;
% subplot(657); ax22 = plot(x, mfmf(x, [3 2 4 6 5], 1.2), '-.k');
% ax22.LineWidth = 1.5;
% grid on; grid minor;
% subplot(658); ax23 = plot(x, mfmf(x, [0 3 6 8 10], 1.2), '-.k');
% ax23.LineWidth = 1.5;
% grid on; grid minor;
% subplot(659); ax24 = plot(x, mfmf(x, [2 3 4 5 6], 1.2), '-.k');
% ax24.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,10); ax25 = plot(x, mfmf(x, [3 2 5 4 6], 1.2), '-.k');
% ax25.LineWidth = 1.5;
% grid on; grid minor;
% %% type-1.3
% % We can write the letter M in 5!=120 different ways
% subplot(6,5,11); ax31 = plot(x, mfmf(x, [2.4 3 3.5 5.5 8],1.3), '-.k');
% ax31.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,12); ax32 = plot(x, mfmf(x, [3 2 4 6 5], 1.3), '-.k');
% ax32.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,13); ax33 = plot(x, mfmf(x, [0 3 6 8 10], 1.3), '-.k');
% ax33.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,14); ax34 = plot(x, mfmf(x, [2 3 4 5 6], 1.3), '-.k');
% ax34.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,15); ax35 = plot(x, mfmf(x, [3 2 5 4 6], 1.3), '-.k');
% ax35.LineWidth = 1.5;
% grid on; grid minor;
% %% type-2
% % We can spawn the letter M in 8!=40,320 different ways
% subplot(6,5,16); ax41 = plot(x, mfmf(x, [2 2.4 3 3.5 5 5.5 6 8], 2), '--.k');
% ax41.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,17); ax42 = plot(x, mfmf(x, [4 4.2 4.6 5 5.2 5.6 5.8 6], 2), '--.k');
% ax42.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,18); ax43 = plot(x, mfmf(x, [0 3.5 5 6 7 8.3 9 10], 2), '--.k');
% ax43.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,19); ax44 = plot(x, mfmf(x, [1 2 3 4 6 7 8 9], 2), '--.k');
% ax44.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,20); ax45 = plot(x, mfmf(x, [1 7 2 6 4 5 8 9], 2), '--.k');
% ax45.LineWidth = 1.5;
% grid on; grid minor;
% %% type-2.2
% % We can spawn the letter M in 8!=40,320 different ways
% subplot(6,5,21); ax51 = plot(x, mfmf(x, [2 2.4 3 3.5 5 5.5 6 8], 2.2), '--.k');
% ax51.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,22); ax52 = plot(x, mfmf(x, [4 4.2 4.6 5 5.2 5.6 5.8 6], 2.2), '--.k');
% ax52.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,23); ax53 = plot(x, mfmf(x, [0 3.5 5 6 7 8.3 9 10], 2.2), '--.k');
% ax53.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,24); ax54 = plot(x, mfmf(x, [1 2 3 4 6 7 8 9], 2.2), '--.k');
% ax54.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,25); ax55 = plot(x, mfmf(x, [1 7 2 6 4 5 8 9], 2.2), '--.k');
% ax55.LineWidth = 1.5;
% grid on; grid minor;
% %% type-2.3
% % We can spawn the letter M in 8!=40,320 different ways
% subplot(6,5,26); ax61 = plot(x, mfmf(x, [2 2.4 3 3.5 5 5.5 6 8], 2.3), '--.k');
% ax61.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,27); ax62 = plot(x, mfmf(x, [4 4.2 4.6 5 5.2 5.6 5.8 6], 2.3), '--.k');
% ax62.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,28); ax63 = plot(x, mfmf(x, [0 3.5 5 6 7 8.3 9 10], 2.3), '--.k');
% ax63.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,29); ax64 = plot(x, mfmf(x, [1 2 3 4 6 7 8 9], 2.3), '--.k');
% ax64.LineWidth = 1.5;
% grid on; grid minor;
% subplot(6,5,30); ax65 = plot(x, mfmf(x, [1 7 2 6 4 5 8 9], 2.3), '--.k');
% ax65.LineWidth = 1.5;
% grid on; grid minor;
% set(mh, 'name', 'M-MF', 'numbertitle', 'off');
%
% Author: Somefun Oluwasegun
% Email: oasomefun@ieee.org
% (c) 2018
% Dept: EEE/CPE, FUTA
if nargin < 3
option = 1;
end
a = cast(params(1),'like',x);
b = cast(params(2),'like',x);
c = cast(params(3),'like',x);
d = cast(params(4),'like',x);
e = cast(params(5),'like',x);
if length(params) > 5
f = cast(params(6),'like',x);
g = cast(params(7),'like',x);
h = cast(params(8),'like',x);
end
y = zeros(size(x));
% if x1 >= x0
% y = cast((x<=(x0+x1)/2),'like',x);
% return;
% end
if option == 1
% a - b
if a < b
id = find( (a <= x) & (x <= 0.5*(a + b)));
if ~isempty(id)
y(id) = 2*((x(id)-a)/(b-a)).^2;
end
id = find( (0.5*(a+b) <= x) & (x <= b));
if ~isempty(id)
y(id) = 1 - 2*((x(id)-b)/(b-a)).^2;
end
else
id = find( (a < x) & (x <= b) );
for idx = min(id):max(id)
y(idx) = cast((x(idx) <= a+b/2),'like',x);
end
end
% b - c
if b < c
id = find( (b < x) & (x <= 0.5*(b + c)));
if ~isempty(id)
y(id) = 1 - 2*((x(id)-b)/(c-b)).^2;
end
id = find( (0.5*(b+c) < x) & (x <= c));
if ~isempty(id)
y(id) = 2*((x(id)-c)/(c-b)).^2;
end
else
id = find( (b < x) & (x <= c) );
for idx = min(id):max(id)
y(idx) = cast((x(idx) <= b+c/2),'like',x);
end
end
% c - d
if c < d
id = find( (c <= x) & (x <= 0.5*(c + d)));
if ~isempty(id)
y(id) = 2*((x(id)-c)/(d-c)).^2;
end
id = find( (0.5*(c+d) <= x) & (x <= d));
if ~isempty(id)
y(id) = 1 - 2*((x(id)-d)/(d-c)).^2;
end
else
id = find( (c < x) & (x <= d) );
for idx = min(id):max(id)
y(idx) = cast((x(idx) <= c+d/2),'like',x);
end
end
% d - e
if d < e
天天Matlab代码科研顾问
- 粉丝: 3w+
- 资源: 2297
最新资源
- 的玩具 Python 实现.zip
- RHCE linux下的火墙管理 及下载
- ESP32-C3FH4 : UltraLowPower SoC with RISCV SingleCore CPU Supporting 2.4 GHz WiFi and Bluetooth LE
- 用于解包和反编译由 Python 代码编译的 EXE 的辅助脚本 .zip
- 用于自动执行任务的精选 Python 脚本列表.zip
- 全国IT学科竞赛蓝桥杯的比赛特点及参赛心得
- 用于编码面试审查的算法和数据结构 .zip
- 用于操作 ESC,POS 打印机的 Python 库.zip
- 用于控制“Universal Robots”机器人的 Python 库.zip
- 用于控制 Broadlink RM2,3 (Pro) 遥控器、A1 传感器平台和 SP2,3 智能插头的 Python 模块.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈