Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[moved] Mat-lab GUI code not running

Status
Not open for further replies.

Muleh

Newbie level 2
Joined
Sep 17, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
32
Code:
function varargout = fl(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name'), mfilename,
...
'gui_Singleton',
gui_Singleton, ...
'gui_OpeningFcn',
@fl_OpeningFcn, ...
'gui_OutputFcn',
@fl_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback =
str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] =
gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% --- Executes on button press in delete.
function delete_Callback(hObject, eventdata,
handles)
% hObject handle to delete (see GCBO)
% eventdata reserved - to be defined in a
future version of MATLAB
% handles structure with handles and user
data (see GUIDATA)
axes(handles.axes1); cla reset
axes(handles.axes2); cla reset
axes(handles.axes3); cla reset
set(handles.t1,'String',' ')
axes(handles.axes7); cla reset
axes(handles.axes8); cla reset
axes(handles.axes9); cla reset
set(handles.t2,'String',' ')
set(handles.t4,'String',' ')
set(handles.et1,'String',' ')
set(handles.t_error,'String',' ')
% --- Executes just before fl is made
visible.
function fl_OpeningFcn(hObject, eventdata,
handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
% --- Outputs from this function are returned
to the command line.
function varargout = fl_OutputFcn(hObject,
eventdata, handles)
% varargout cell array for returning output
args (see
% Get default command line output from
handles structure
varargout{1} = handles.output;
% --- Executes on button press in b.
function b_Callback(hObject, eventdata,
handles)
% hObject handle to b (see GCBO)
global th_ph_f;
global dlg_ab;
global l2l_ab;
global slf_A;
global D;
th_ph_f=0; dlg_ab=0; l2l_ab=0; slf_A=0; D=0;
file = uigetfile('*.csv');
newData1 = importdata(file);
% Create new variables in the base workspace
from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', vars{i},
newData1.(vars{i}));
end
data = newData1.(vars{1});
t=data(1:20000,1);
A =data(1:20000,2);
B =data(1:20000,3);
C =data(1:20000,4);
I0 = (1/3)* (A+B+C);
I1 = (1/3)*(2*A - B -C);
I2 = (1/3)*(sqrt(3)*B - sqrt(3)*C);
% Perform a multilevel wavelet decomposition
of I0 at level 5
[C0,L0] = wavedec(I0,5,'db4');
[Ea0,Ed0] = wenergy(C0,L0);
% Extract approximation and detail
coefficients.
c0A5 = appcoef(C0,L0,'db4',5);
c0A4 = appcoef(C0,L0,'db4',4);
c0A3 = appcoef(C0,L0,'db4',3);
c0A2 = appcoef(C0,L0,'db4',2);
c0A1 = appcoef(C0,L0,'db4',1);
c0D5 = detcoef(C0,L0,5);
c0D4 = detcoef(C0,L0,4);
c0D3 = detcoef(C0,L0,3);
c0D2 = detcoef(C0,L0,2);
c0D1 = detcoef(C0,L0,1);
%Energy for 1-D wavelet or wavelet packet
decomposition
[Ea0,Ed0] = wenergy(C0,L0);
Ed0_max = max(Ed0);
% Reconstruct the Level 5 approximation and
the Level 1 to 9 details.
A05 = wrcoef('a',C0,L0,'db4',5);
D01 = wrcoef('d',C0,L0,'db4',1);
D02 = wrcoef('d',C0,L0,'db4',2);
D03 = wrcoef('d',C0,L0,'db4',3);
D04 = wrcoef('d',C0,L0,'db4',4);
D05 = wrcoef('d',C0,L0,'db4',5);
% Evaluation of the square of the wavelet
coefficients
s_D01=D01.*D01; sum_s_D01=sum(s_D01);
s_D02=D02.*D02; sum_s_D02=sum(s_D02);
s_D03=D03.*D03; sum_s_D03=sum(s_D03);
s_D04=D04.*D04; sum_s_D04=sum(s_D04);
s_D05=D05.*D05; sum_s_D05=sum(s_D05);
% caculation of the disotrted signal
energy%%%%
d01=sum_s_D01;
d02=d01+sum_s_D02;
d03=d02+sum_s_D03;
d04=d03+sum_s_D04;
d05=d04+sum_s_D05;
% Perform a multilevel wavelet decomposition
of phase A at level 5
[Ca,La] = wavedec(A,5,'db4');
% Extract approximation and detail
coefficients.
caA5 = appcoef(Ca,La,'db4',5);
caA4 = appcoef(Ca,La,'db4',4);
caA3 = appcoef(Ca,La,'db4',3);
caA2 = appcoef(Ca,La,'db4',2);
caA1 = appcoef(Ca,La,'db4',1);
caD5 = detcoef(Ca,La,5);
caD4 = detcoef(Ca,La,4);
caD3 = detcoef(Ca,La,3);
caD2 = detcoef(Ca,La,2);
caD1 = detcoef(Ca,La,1);
% Reconstruct the Level 5 approximation and
the Level 1 to 5 details.
Aa5 = wrcoef('a',Ca,La,'db4',11);
Da1 = wrcoef('d',Ca,La,'db4',1);
Da2 = wrcoef('d',Ca,La,'db4',2);
Da3 = wrcoef('d',Ca,La,'db4',3);
Da4 = wrcoef('d',Ca,La,'db4',4);
Da5 = wrcoef('d',Ca,La,'db4',5);
%Energy for 1-D wavelet or wavelet packet
decomposition
[Eaa,Eda] = wenergy(Ca,La);
Eda_max = max(Eda);
% Evaluation of the square of the wavelet
coefficients
s_Da1=Da1.*Da1; sum_s_Da1=sum(s_Da1);
s_Da2=Da2.*Da2; sum_s_Da2=sum(s_Da2);
s_Da3=Da3.*Da3; sum_s_Da3=sum(s_Da3);
s_Da4=Da4.*Da4; sum_s_Da4=sum(s_Da4);
s_Da5=Da5.*Da5; sum_s_Da5=sum(s_Da5);
% caculation of the disotrted signal
energy%%%%
da1=sum_s_Da1;
da2=da1+sum_s_Da2;
da3=da2+sum_s_Da3;
da4=da3+sum_s_Da4;
da5=da4+sum_s_Da5;
% Perform a multilevel wavelet decomposition
of phase B at level 5
[Cb,Lb] = wavedec(B,5,'db4');
% Extract approximation and detail
coefficients.
cbA5 = appcoef(Cb,Lb,'db4',5);
cbA4 = appcoef(Cb,Lb,'db4',4);
cbA3 = appcoef(Cb,Lb,'db4',3);
cbA2 = appcoef(Cb,Lb,'db4',2);
cbA1 = appcoef(Cb,Lb,'db4',1);
cbD5 = detcoef(Cb,Lb,5);
cbD4 = detcoef(Cb,Lb,4);
cbD3 = detcoef(Cb,Lb,3);
cbD2 = detcoef(Cb,Lb,2);
cbD1 = detcoef(Cb,Lb,1);
% Reconstruct the Level 5 approximation and
the Level 1 to 5 details.
Ab5 = wrcoef('a',Cb,Lb,'db4',1);
Db1 = wrcoef('d',Cb,Lb,'db4',1);
Db2 = wrcoef('d',Cb,Lb,'db4',2);
Db3 = wrcoef('d',Cb,Lb,'db4',3);
Db4 = wrcoef('d',Cb,Lb,'db4',4);
Db5 = wrcoef('d',Cb,Lb,'db4',5);
%Energy for 1-D wavelet or wavelet packet
decomposition
[Eab,Edb] = wenergy(Cb,Lb);
Edb_max = max(Edb);
% Evaluation of the square of the wavelet
coefficients
s_Db1=Db1.*Db1; sum_s_Db1=sum(s_Db1);
s_Db2=Db2.*Db2; sum_s_Db2=sum(s_Db2);
s_Db3=Db3.*Db3; sum_s_Db3=sum(s_Db3);
s_Db4=Db4.*Db4; sum_s_Db4=sum(s_Db4);
s_Db5=Db5.*Db5; sum_s_Db5=sum(s_Db5);
% caculation of the disotrted signal
energy%%%%
db1=sum_s_Db1;
db2=db1+sum_s_Db2;
db3=db2+sum_s_Db3;
db4=db3+sum_s_Db4;
db5=db4+sum_s_Db5;
% Perform a multilevel wavelet decomposition
of phase C at level 5
[Cc,Lc] = wavedec(C,5,'db4');
% Extract approximation and detail
coefficients.
ccA5 = appcoef(Cc,Lc,'db4',5);
ccA4 = appcoef(Cc,Lc,'db4',4);
ccA3 = appcoef(Cc,Lc,'db4',3);
ccA2 = appcoef(Cc,Lc,'db4',2);
ccA1 = appcoef(Cc,Lc,'db4',1);
ccD5 = detcoef(Cc,Lc,5);
ccD4 = detcoef(Cc,Lc,4);
ccD3 = detcoef(Cc,Lc,3);
ccD2 = detcoef(Cc,Lc,2);
ccD1 = detcoef(Cc,Lc,1);
% Reconstruct the Level 5 approximation and
the Level 1 to 5 details.
Ac5 = wrcoef('a',Cc,Lc,'db4',11);
Dc1 = wrcoef('d',Cc,Lc,'db4',1);
Dc2 = wrcoef('d',Cc,Lc,'db4',2);
Dc3 = wrcoef('d',Cc,Lc,'db4',3);
Dc4 = wrcoef('d',Cc,Lc,'db4',4);
Dc5 = wrcoef('d',Cc,Lc,'db4',5);
%Energy for 1-D wavelet or wavelet packet
decomposition
[Eac,Edc] = wenergy(Cc,Lc);
Edc_max = max(Edc);
% Evaluation of the square of the wavelet
coefficients
s_Dc1=Dc1.*Dc1; sum_s_Dc1=sum(s_Dc1);
s_Dc2=Dc2.*Dc2; sum_s_Dc2=sum(s_Dc2);
s_Dc3=Dc3.*Dc3; sum_s_Dc3=sum(s_Dc3);
s_Dc4=Dc4.*Dc4; sum_s_Dc4=sum(s_Dc4);
s_Dc5=Dc5.*Dc5; sum_s_Dc5=sum(s_Dc5);
% caculation of the disotrted signal
energy%%%%
dc1=sum_s_Dc1;
dc2=dc1+sum_s_Dc2;
dc3=dc2+sum_s_Dc3;
dc4=dc3+sum_s_Dc4;
dc5=dc4+sum_s_Dc5;
axes(handles.axes1);
plot(t,A );hold on; plot(t, Aa5,'r');
axes(handles.axes2);
plot(t,B,'.' );hold on; plot(t, Ab5,'r')
axes(handles.axes3);
plot(t,C );hold on; plot(t, Ac5,'r')
axes(handles.axes4);
imshow('panel.png')
axes(handles.axes5);
imshow('panel_b.png')
axes(handles.axes6);
imshow('panel_c.png')
set(handles.t1,'String',file)
axes(handles.axes7); plot(t,Da5);
axes(handles.axes8); plot(t,Db5);
axes(handles.axes9); plot(t,Db5);
% no fault
if (da5<15) && (db5<15) && (dc5<15)
set(handles.t2,'String','No Fault')
Fault=0;
else
Fault=1;
end
%%%%%% Fault Classification
%%%%%
if Fault==1
FUZ = readfis('class');
clas = evalfis([Ed0_max Eda_max Edb_max
Edc_max ], FUZ)
if (clas>0.5)&& (clas<1.5)
set(handles.t2,'String','Three Phase
Fault')
th_ph_f= 1;
elseif (clas>1.5)&& (clas<2.5)
set(handles.t2,'String','Double line to
ground Fault between phase A and B')
dlg_ab=1;
elseif (clas>2.5)&& (clas<3.5)
set(handles.t2,'String','line to line
Fault between phase A and B')
l2l_ab=1;
elseif (clas>3.5)&& (clas<4.5)
set(handles.t2,'String','Single line to
ground Fault at phase A')
slf_A=1;
else
set(handles.t2,'String','Wrong')
end
%%%%%%%% Fault location
%%%%%%%%%%%%%%%
if th_ph_f==1
FUZ = readfis('anfis_3ph');
D = evalfis([Ed0_max Eda_max Edb_max Edc_max
], FUZ)
set(handles.t4,'String',D);
end
if slf_A == 1
FUZ = readfis('anfis_slg');
D = evalfis([Ed0_max Eda_max Edb_max Edc_max
], FUZ)
set(handles.t4,'String',D);
end
if l2l_ab == 1
FUZ = readfis('anfis_l2l');
D = evalfis([Ed0_max Eda_max Edb_max Edc_max
], FUZ)
set(handles.t4,'String',D);
end
if dlg_ab ==1
FUZ = readfis('anfis_dlg');
D = evalfis([Ed0_max Eda_max Edb_max Edc_max
], FUZ)
set(handles.t4,'String',D);
end
end
function et1_Callback(hObject, eventdata,
handles)
function et1_CreateFcn(hObject, eventdata,
handles)
if ispc &&
isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in calc_error.
function calc_error_Callback(hObject,
eventdata, handles)
d = get(handles.t4,'String');
d_val = str2double(d);
AFL = get(handles.et1,'String');
AFL_val = str2double(AFL);
error = 100 * abs(AFL_val-d_val)/6 ;
set(handles.t_error,'String',error);
A.2 Creating and Training the ANFIS MODEL
files_names = dir(fullfile(matlabroot,
'anfis'));
no_files = length (files_names);
for nf=3:no_files
fp = files_names(nf).name;
savefile = 'trnError_3ph.csv';
file_Path = ['C:\Program
Files\MATLAB2\R2011a\anfis\' , fp];
importfile_anfis(file_Path)
trnData = train_3ph;
numMFs = 5;
mfType = 'gbellmf';
in_fis = genfis1(trnData,numMFs,mfType);
[out_fis,trnError_class] = anfis(trnData,
in_fis,300);
plot(trnError_class , '*');grid;
xlabel('Epochs');
ylabel('RMSE (Root Mean Squared Error)');
title('Error Curves');
figure(2)
out_fis_o = evalfis(trnData(:,1:4),out_fis);
plot([out_fis_o ,trnData(:,5)], 'x');
end
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top