15 November 2018 3 852 Report

Hi

i'm having a hard time working with Fuzzy toolbox in matlab, i have made a fis, i have added my desired membership functions for input and outputs. Now i want to generate fuzzy rules based on my Data set for input/output. I have 1000 input data and their 1000 output data. what should i do?

this is my code

%% Fuzzy Inference System Definition

MyFuzzySystem=newfis('Amin');

MyFuzzySystem=addvar(MyFuzzySystem,'input','theta',[-40 40]);

MyFuzzySystem=addvar(MyFuzzySystem,'output','x',[0 20]);

MyFuzzySystem=addvar(MyFuzzySystem,'output','y',[0 10]);

%% Adding MFs to the theta input

MyFuzzySystem=addmf(MyFuzzySystem,'input',1,'','trapmf',[-40 -40 -39.2 -38.4]); %A1

for i=2:99

MyFuzzySystem=addmf(MyFuzzySystem,'input',1,'','trimf',[0.8*i-40.8 0.8*i-40 0.8*i-39.2]); %%A2-A99

end

MyFuzzySystem=addmf(MyFuzzySystem,'input',1,'','trapmf',[38.4 39.2 40 40]); %A100

%mfedit(MyFuzzySystem)

%plotmf(MyFuzzySystem,'input',1);

%% Adding MFs to the x output

for i=1:101

MyFuzzySystem=addmf(MyFuzzySystem,'output',1,'','trimf',[0.2*(i-2) 0.2*(i-1) 0.2*(i)]); %%B1-B101

end

%% Adding MFs to the y output

for i=1:101

MyFuzzySystem=addmf(MyFuzzySystem,'output',2,'','trimf',[0.1*(i-2) 0.1*(i-1) 0.1*(i)]); %%C1-C101

end

%mfedit(MyFuzzySystem)

%% Generating Input-Output Data

%%% Generating theta

phi=rand(100,1)*2*pi;

omega=rand(100,1)*50;

theta=zeros(1,1000);

alpha=zeros(100,1000);

for i=1:100

for t=1:1:1000

alpha(i,t)=(((40/sqrt(2))*(sin(omega(i,1)*(t/100)+phi(i,1))+cos(omega(i,1)*(t/100)+phi(i,1)))));

end

end

for k=1:1000

sum_alpha=0;

for w=1:100

sum_alpha=sum_alpha+alpha(w,k);

end

theta(1,k)=sum_alpha/100;

end

subplot(2,2,1);

t=1:1000;

y=(40/11)*theta;

theta_degree=theta*(pi/180);

plot(t/100,y);

xlabel('t');

ylabel('theta(t)');

xlim=[0,10];

ylim=[-40,40];

%%% Calculating phi

b=10;

phi_out(1,1)=45;

for i=1:999

phi_out(1,i+1)=phi_out(1,i)-asin((2*sin(theta_degree(1,i)))/b);

end

subplot(2,2,2);

t=1:1000;

plot(t/100,phi_out);

xlabel('t');

ylabel('phi(t)');

%%% Calculating x(t), y(t)

x_out(1,1)=0;

y_out(1,1)=0;

for i=1:999

x_out(1,i+1)=x_out(1,i)+cos(phi_out(1,i)+theta_degree(1,i))+sin(theta_degree(1,i)).*sin(phi_out(1,i));

y_out(1,i+1)=y_out(1,i)+sin(phi_out(1,i)+theta_degree(1,i))-sin(theta_degree(1,i)).*cos(phi_out(1,i));

end

subplot(2,2,3);

plot(x_out,y_out)

xlabel('x');

ylabel('y');

InputOutputData=[theta' x_out' y_out'];

More Amin Moradi's questions See All
Similar questions and discussions