Info

此问题已关闭。 请重新打开它进行编辑或回答。

Need help with debugging

3 次查看(过去 30 天)
soloby
soloby 2015-7-11
关闭: MATLAB Answer Bot 2021-8-20
Hey all, below is my coding which does fuzzy operation (addition, subtraction, multiplication, division)
My issue is that the upper limit after multiplying is completely different from what it should be (subplot 2,5,4 part) anyone have an idea why?
I dont know how I can have just that one part go wrong when the other operations work just fine.. Help!
clear
clc
x = -10:0.1:10;
f1 = trapmf(x,[-2 0 0 4]);
f2 = trapmf(x,[-1 3 3 5]);
%f2 = gaussmf(x,[2,5])
f1print = roundn(f1,-2);
f2print = roundn(f2,-2);
kvals = 0.05:0.05:1;
for kidx = 1 : length(kvals)
k = kvals(kidx);
index1 = find(abs(f1print-k)<10^-3)
Xidx1{kidx} = x(index1);
Xidx1{20} = [0 0];
index2 = find(abs(f2print-k)<10^-3);
Xidx2{kidx} = x(index2);
Xidx2{20} = [0 0];
A(kidx) = Xidx1{kidx}(1);
B(kidx) = Xidx1{kidx}(2);
C(kidx) = Xidx2{kidx}(1);
D(kidx) = Xidx2{kidx}(2);
end
%Multiplication
E = [A.*C; A.*D ;B.*C ;C.*D ];
F = min(E);
G = -F;
Z = max(E);
%Division
H = [A./C;A./D;B./C;B./D];
I = min(H);
J = max(H);
subplot(2,5,1)
plot(x,f1)
title('1');
subplot(2,5,6)
plot(x,f2)
title('2');
subplot(2,5,2)
plot(A+C,kvals,B+D,kvals)
title('1 + 2');
axis([-2 8 0.05 0.95]);
subplot(2,5,7)
plot(x,fuzarith(x,f1,f2,'sum'))
title('1 + 2 Built-In');
axis([-2 8 0.05 0.95]);
subplot(2,5,3)
plot(A-D,kvals,B-C,kvals)
title('1 - 2');
axis([-9 3 0.05 0.95]);
subplot(2,5,8)
plot(x,fuzarith(x,f1,f2,'sub'))
title('1 - 2 Built-In');
axis([-9 3 0.05 0.95]);
subplot(2,5,4)
plot(F,kvals, Z,kvals)
title('1 * 2');
axis([-10 10 0.05 0.95]);
subplot(2,5,9)
plot(x,fuzarith(x,f1,f2,'prod'));
title('1 * 2 Built-In');
axis([-10 10 0.05 0.95]);
subplot(2,5,5)
plot(I,kvals,J,kvals)
title('1 / 2');
axis([-2 2 0.05 0.95]);
subplot(2,5,10)
plot(x,fuzarith(x,f1,f2,'div'));
title('1 / 2 Built-In');
axis([-2 2 0.05 0.95]);

回答(0 个)

此问题已关闭。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by