📄 haha.m
字号:
function varargout = lishuaidegui(varargin)
% LISHUAIDEGUI M-file for lishuaidegui.fig
% LISHUAIDEGUI, by itself, creates a new LISHUAIDEGUI or raises the existing
% singleton*.
%
% H = LISHUAIDEGUI returns the handle to a new LISHUAIDEGUI or the handle to
% the existing singleton*.
%
% LISHUAIDEGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LISHUAIDEGUI.M with the given input arguments.
%
% LISHUAIDEGUI('Property','Value',...) creates a new LISHUAIDEGUI or raises
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before lishuaidegui_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to lishuaidegui_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help lishuaidegui
% Last Modified by GUIDE v2.5 13-Nov-2005 17:11:51
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @lishuaidegui_OpeningFcn, ...
'gui_OutputFcn', @lishuaidegui_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
% End initialization code - DO NOT EDIT
% --- Executes just before lishuaidegui is made visible.
function lishuaidegui_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 lishuaidegui (see VARARGIN)
handles.ii=1;
% Choose default command line output for lishuaidegui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes lishuaidegui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = lishuaidegui_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 selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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 popupmenu1 contents as cell
% contents{get(hObject,'Value')} returns selected item from popupmenu1
val=get(hObject,'Value');
str= get(hObject,'String');
switch str{val}
case '第一类'
handles.ii=1;
case '第二类'
handles.ii=2;
case '第三类'
handles.ii=3;
end
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObect,'String')returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
handles.currentdata=str2num(get(handles.edit1,'string'));%
hold on
switch handles.ii,
case 1,
handles.x1=handles.currentdata;
plot(handles.x1(1,:),handles.x1(2,:),'o');
title('您所输入的第一类样本点')
case 2,
handles.x2=handles.currentdata;
plot(handles.x2(1,:),handles.x2(2,:),'+')
title('您所输入的第二类样本点');
case 3,
handles.x3=handles.currentdata;
plot(handles.x3(1,:),handles.x3(2,:),'*')
title('您所输入的第三类样本点');
end
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
axis([-10,10,-10,10])
% Hint: edit 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 button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x1=handles.x1';
x2=handles.x2';
x3=handles.x3';
w1=ones(1,3);w2=ones(1,3);w3=ones(1,3);
[r1,q1]=size(x1);[r2,q2]=size(x2);[r3,q3]=size(x3);
x=[x1,x2,x3;ones(1,q1+q2+q3)];
i=1;n=0;num=0;k=.1;
while i<q1+q2+q3+13,
d1=w1*x(:,i);
d2=w2*x(:,i);
d3=w3*x(:,i);
%switch i,
if (1<=i)&(i<=q1),
w=w1;
if d2>=d1,
w1=w+k*x(:,i)';
w2=w2-k*x(:,i)';
n=0;
end
if d3>=d1,
w1=w+k*x(:,i)';
w3=w3-k*x(:,i)';
n=0;
end
if (d2<d1)&(d3<d1)
n=n+1;
end
if n>q1+q2+q3
break
end
elseif ((q1+1)<=i)&(i<=(q1+q2)),
w=w2;
if d1>=d2
w2=w+k*x(:,i)';
w1=w1-k*x(:,i)';
n=0;
end
if d3>=d2
w2=w+k*x(:,i)';
w3=w3-k*x(:,i)';
n=0;
end
if (d2>d1)&(d3<d2)
n=n+1;
end
if n>q1+q2+q3
break;
end
elseif ((q1+q2+1)<=i)&(i<=(q1+q2+q3)),
w=w3;
if d1>=d3
w3=w+k*x(:,i)';
w1=w1-k*x(:,i)';
n=0;
end
if d2>=d3
w3=w+k*x(:,i)';
w2=w2-k*x(:,i)';
n=0;
end
if (d2<d3)&(d3>d1)
n=n+1;
end
if n>q1+q2+q3
break;
end
end
if i>=q1+q2+q3
i=1;
else i=i+1;%i,n,num
end
num=num+1;
if num>=9000
break
end
end
hold off,
plot(x(1,1:q1),x(2,1:q1),'o',x(1,q1+1:q1+q2),x(2,q1+1:1+q2)...
,'+',x(1,q1+q2+1:q1+q2+q3),x(2,q1+q2+1:q1+q2+q3),'*') %
p=minmax(x(1,:));%
pm=-(-w1(3)*w3(2)-w2(3)*w1(2)+...
w2(3)*w3(2)+w1(3)*w2(2)+w3(3)*w1(2)-w3(3)*w2(2))/...
(-w1(1)*w3(2)-w2(1)*w1(2)+w2(1)*w3(2)+w1(1)*w2(2)...
+w3(1)*w1(2)-w3(1)*w2(2));
xmin=p(1);
xmax=p(2);
xx=[xmin,pm,xmax];
yy1=(-(w1(3)-w2(3))-(w1(1)-w2(1))*xx)/(w1(2)-w2(2));
yy2=(-(w1(3)-w3(3))-(w1(1)-w3(1))*xx)/(w1(2)-w3(2));
yy3=(-(w3(3)-w2(3))-(w3(1)-w2(1))*xx)/(w3(2)-w2(2));
xy1=[xmin;yy1(1);1];
xy2=[xmin;yy2(1);1];
xy3=[xmin;yy3(1);1];
d11=w1*xy1;
d12=w2*xy1;
d13=w3*xy1;
d21=w1*xy2;
d22=w2*xy2;
d23=w3*xy2;
d31=w1*xy3;
d32=w2*xy3;
d33=w3*xy3;
if n>=q1+q2+q3
if(d13>d12)&(d13>d11)
hold on,plot(xx(1,2:3),yy1(1,2:3),'r');
else
hold on,plot(xx(1,1:2),yy1(1,1:2),'r');
end
if(d22>d21)&(d22>d23)
hold on,plot(xx(1,2:3),yy2(1,2:3),'g');
else
hold on,plot(xx(1,1:2),yy2(1,1:2),'g');
end
if(d31>d32)&(d31>d33)
hold on,plot(xx(1,2:3),yy3(1,2:3),'b');
else
hold on,plot(xx(1,1:2),yy3(1,1:2),'b');
end
title('判决面如下')
else %输出训练次数达到阈值
hold on,title('训练次数达到阈值')
end
guidata(hObject,handles)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in restartpushbutton8.
function restartpushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to restartpushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hold off
plot(0,0);
axis([-10,10,-10,10])
title('请重新输入')
% --- Executes on button press in outpushbutton9.
function outpushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to outpushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
exit
% --- Executes on button press in sbpushbutton10.
function sbpushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to sbpushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.currentdata=ginput;
hold on
switch handles.ii
case 1,
handles.x1=handles.currentdata;
plot(handles.x1(:,1),handles.x1(:,2),'o');
axis([-10,10,-10,10])
title('您所输入的第一类样本点')
case 2,
handles.x2=handles.currentdata;
plot(handles.x2(:,1),handles.x2(:,2),'+')
axis([-10,10,-10,10])
title('您所输入的第二类样本点');
case 3,
handles.x3=handles.currentdata;
plot(handles.x3(:,1),handles.x3(:,2),'*')
axis([-10,10,-10,10])
title('您所输入的第三类样本点');
end
guidata(hObject,handles)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -