⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 利用matlab编程神经网络与其界面.txt

📁 这是利用MATLAB图形用户界面设计技术设计的一个关于基于神经网络的变压器故障诊断系统,全部语言用MATLAB所编,途中还涉及三比值法 无编码法的MATLAB编程程序.
💻 TXT
字号:
function varargout = bsbptrain(varargin)
% BSBPTRAIN M-file for bsbptrain.fig
%      BSBPTRAIN, by itself, creates a new BSBPTRAIN or raises the existing
%      singleton*.
%
%      H = BSBPTRAIN returns the handle to a new BSBPTRAIN or the handle to
%      the existing singleton*.
%
%      BSBPTRAIN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in BSBPTRAIN.M with the given input arguments.
%
%      BSBPTRAIN('Property','Value',...) creates a new BSBPTRAIN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before bsbptrain_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to bsbptrain_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help bsbptrain
% Last Modified by GUIDE v2.5 31-May-2006 17:04:22
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @bsbptrain_OpeningFcn, ...
                   'gui_OutputFcn',  @bsbptrain_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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
% End initialization code - DO NOT EDIT
% --- Executes just before bsbptrain is made visible.
function bsbptrain_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to bsbptrain (see VARARGIN)
% Choose default command line output for bsbptrain
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes bsbptrain wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = bsbptrain_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in training_pushbutton.
function training_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to training_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clear;
clc;
global counter;
h = findobj('Tag','type_popupmenu');
typeValue = get(h,'Value');
if typeValue == 1
    str1(1) = {'%NEWRBE精确设计一个径向基函数网络;'};
    str1(2) = {'%SIM对径向基网络进行仿真;'};
else
    str1(1) = {'%NEWFF 生成一个新的前向神经网络;'};
    str1(2) = {'%TRAIN 对BP网络进行训练;'};
    str1(3) = {'%SIM 对BP网络进行仿真。'};
end
h = findobj('Tag','miniWindow_text');
set(h,'String',str1);
counter = 1;
h = findobj('Tag','next_pushbutton');
set(h,'Enable','on');
h = findobj('Tag','training_pushbutton');
set(h,'Enable','off');
h = findobj('Tag','test_pushbutton');
set(h,'Enable','off');
h = findobj('Tag','type_popupmenu');
set(h,'Enable','off');
h = findobj('Tag','iec_pushbutton');
set(h,'Enable','off');
h = findobj('Tag','nocode_pushbutton');
set(h,'Enable','off');
% --- Executes on button press in next_pushbutton.
function next_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to next_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global counter P T net;
h = findobj('Tag','next_pushbutton');
set(h,'Enable','off');
switch counter
  case 1
    str1(1) = {'%第一步:'};
    str1(2) = {'%定义训练样本;'};
    str1(3) = {'%读入表格数据;'};
    str1(4) = {'%P为输入矢量(训练样本集);'};
    str1(5) = {'%T为目标矢量(训练样本集);'};
    h = findobj('Tag','miniWindow_text');
    set(h,'String',str1);
    data = xlsread('five.xls');
    P = [   data(1:93,2)';
            data(1:93,3)';
            data(1:93,4)';
            data(1:93,5)';
            data(1:93,6)'   ] 
    T =  [  data(1:93,7)';
            data(1:93,8)';
            data(1:93,9)';
            data(1:93,10)';
            data(1:93,11)';
            data(1:93,12)'  ]
  case 2
    h = findobj('Tag','type_popupmenu');
    typeValue = get(h,'Value');
    if typeValue == 1
        str1(1) = {'%第二步:'};
        str1(2) = {'%开启秒表;'};
        str1(3) = {'%设计一个新的径向基神经网络(网络输入维数为5,输出维数为6);'};
        h = findobj('Tag','miniWindow_text');
        set(h,'String',str1);
        tic
        net = newrbe(P,T,0.0001);
        toc
    else
        str1(1) = {'%第二步:'};
        str1(2) = {'%开启秒表;'};
        str1(3) = {'%创建一个新的前向神经网络(网络输入维数为5,输出维数为6,网络中间层神经元数目预选为15);'};
        str1(4) = {'%设置训练参数;'};
        str1(5) = {'%调用TRAINGDM算法训练BP网络;'};
        h = findobj('Tag','miniWindow_text');
        set(h,'String',str1);
        tic;
        if typeValue == 2
            net = newff(minmax(P),[15,6],{'tansig','purelin'},'trainlm');
        else
            net = newff(minmax(P),[15,6],{'tansig','purelin'},'trainbr');
        end
        net.trainParam.show = 50;
        net.trainParam.Ir = 0.05;
        net.trainParam.mc = 0.9;
        net.trainParam.epochs = 1500;
        net.trainParam.goal = 1e-3;
        [net,tr] = train(net,P,T);
        toc
    end
  case 3
    str1(1) = {'%第三步:'};
    str1(2) = {'%对BP网络进行仿真;'};
    h = findobj('Tag','miniWindow_text');
    set(h,'String',str1);
    A = sim(net,P)
    E = T - A
    MSE = mse(E)
  case 4
    str1(1) = {'%第四步:'};
    str1(2) = {'%存储训练后的网络;'};
    h = findobj('Tag','miniWindow_text');
    set(h,'String',str1);
    h = findobj('Tag','type_popupmenu');
    typeValue = get(h,'Value');
    switch typeValue
        case 1 
            save readyrbf net;
        case 2
            save readybp1 net;
        case 3
            save readybp3 net;
    end
    h = findobj('Tag','training_pushbutton');
    set(h,'Enable','on');
    h = findobj('Tag','test_pushbutton');
    set(h,'Enable','on');
    h = findobj('Tag','type_popupmenu');
    set(h,'Enable','on');
    h = findobj('Tag','iec_pushbutton');
    set(h,'Enable','on');
    h = findobj('Tag','nocode_pushbutton');
    set(h,'Enable','on');
end
if counter ~= 4
    h = findobj('Tag','next_pushbutton');
    set(h,'Enable','on');
end    
counter = counter + 1;
% --- Executes during object creation, after setting all properties.
function type_popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to type_popupmenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
   set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in type_popupmenu.
function type_popupmenu_Callback(hObject, eventdata, handles)
% hObject    handle to type_popupmenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns type_popupmenu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from type_popupmenu
% --- Executes on button press in test_pushbutton.
function test_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to test_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
str1(1) = {'%加载训练后的BP网络;'};
str1(2) = {'%测试输入向量;'};
str1(3) = {'%读入表格数据;'};
str1(4) = {'%p为输入矢量(测试样本集);'};
str1(5) = {'%仿真输出结果;'};
h = findobj('Tag','miniWindow_text');
set(h,'String',str1);
h = findobj('Tag','type_popupmenu');
typeValue = get(h,'Value');
switch typeValue
    case 1 
        load readyrbf net;
    case 2
        load readybp1 net;
    case 3
        load readybp3 net;
end
data = xlsread('fivec.xls');
z = 25;
p = [   data(1:z,2)';
        data(1:z,3)';
        data(1:z,4)';
        data(1:z,5)';
        data(1:z,6)'    ]
a2 = sim(net,p)
for i=1:6
    for j=1:z
        if (a2(i,j)>0.5) a2(i,j)=1;
        else a2(i,j)=0;
        end
    end
end
a2
% --- Executes on button press in close_pushbutton.
function close_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to close_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close all;
% --- Executes on button press in iECthree_pushbutton.
function iECthree_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to iECthree_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clear;
clc;
str1(1) = {'%运用IEC改良三比值法进行故障诊断:'};
str1(2) = {'%读入表格数据;'};
str1(3) = {'%p为输入矢量;'};
str1(4) = {'%输出结果;'};
h = findobj('Tag','miniWindow_text');
set(h,'String',str1);
data = xlsread('fivec.xls');
z = 25;
p = [   data(1:z,2)';
        data(1:z,3)';
        data(1:z,4)';
        data(1:z,5)';
        data(1:z,6)'    ]
for j=1:z
        if (p(5,j)/p(4,j)<0.1) a(1,j)=0; 
        elseif (p(5,j)/p(4,j)>=0.1&p(5,j)/p(4,j)<3) a(1,j)=1;
        else a(1,j)=2;
        end
end
for j=1:z
        if (p(2,j)/p(1,j)<0.1) a(2,j)=1; 
        elseif (p(2,j)/p(1,j)>=0.1&p(2,j)/p(1,j)<1) a(2,j)=0;
        else a(2,j)=2;
        end
end
for j=1:z
        if (p(4,j)/p(3,j)<1) a(3,j)=0; 
        elseif (p(4,j)/p(3,j)>=1&p(4,j)/p(3,j)<3) a(3,j)=1;
        else a(3,j)=2;
        end
end
a
for j=1:z
    if (a(:,[j])==[0;0;0]) a2(1,j)=0;
    elseif (a(:,[j])==[0;0;1]) a2(1,j)=1;
    elseif (a(:,[j])==[0;2;0])  a2(1,j)=2;
    elseif (a(:,[j])==[0;2;1])  a2(1,j)=3;
    elseif (a(:,[j])==[0;0;2]|a(:,j)==[0;1;2]|a(:,j)==[0;2;2])  a2(1,j)=4;
    elseif (a(:,[j])==[0;1;0])  a2(1,j)=5; 
    elseif (a(:,[j])==[2;0;0]|a(:,j)==[2;0;1]|a(:,j)==[2;0;2]|a(:,j)==[2;1;0]|a(:,j)==[2;1;1]|a(:,j)==[2;1;2])  a2(1,j)=6;
    elseif (a(:,[j])==[2;2;0]|a(:,j)==[2;2;1]|a(:,j)==[2;2;2])  a2(1,j)=7; 
    elseif (a(:,[j])==[1;0;0]|a(:,j)==[1;0;1]|a(:,j)==[1;0;2]|a(:,j)==[1;1;0]|a(:,j)==[1;1;1]|a(:,j)==[1;1;2])  a2(1,j)=8; 
    elseif (a(:,[j])==[1;2;0]|a(:,j)==[1;2;1]|a(:,j)==[1;2;2])  a2(1,j)=9;
    else a2(1,[j])=10;
    end
end
a2

% --- Executes on button press in nocode_pushbutton.
function nocode_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to nocode_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clear;
clc;
str1(1) = {'%运用无编码比值法进行故障诊断:'};
str1(2) = {'%读入表格数据;'};
str1(3) = {'%p为输入矢量;'};
str1(4) = {'%输出结果;'};
h = findobj('Tag','miniWindow_text');
set(h,'String',str1);
data = xlsread('fivec.xls');
z = 25;
p = [   data(1:z,2)';
        data(1:z,3)';
        data(1:z,4)';
        data(1:z,5)';
        data(1:z,6)'    ]
for j=1:z
    a(1,j)=p(5,j)/p(4,j); 
    a(2,j)=p(2,j)/p(1,j);
    a(3,j)=p(4,j)/p(3,j);
end
a
for j=1:z
    if (a(1,j)<0.1&a(3,j)<1) a2(1,j)=2;
    elseif (a(1,j)<0.1&a(3,j)>1&a(3,j)<3) a2(1,j)=3;
    elseif (a(1,j)<0.1&a(3,j)>3) a2(1,j)=4;
    elseif (a(1,j)>0.1&a(1,j)<3&a(2,j)<1) a2(1,j)=8;
    elseif (a(1,j)>0.1&a(1,j)<3&a(2,j)>1) a2(1,j)=9; 
    elseif (a(1,j)>3&a(2,j)<1) a2(1,j)=6;
    elseif (a(1,j)>3&a(2,j)>1) a2(1,j)=7; 
    else a2(1,[j])=10;
    end
end
a2

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -