function varargout = test(varargin)
% TEST MATLAB code for test.fig
% TEST, by itself, creates a new TEST or raises the existing
% singleton*.
%
% H = TEST returns the handle to a new TEST or the handle to
% the existing singleton*.
%
% TEST('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TEST.M with the given input arguments.
%
% TEST('Property','Value',...) creates a new TEST or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before test_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to test_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 test
% Last Modified by GUIDE v2.5 29-Sep-2014 09:27:33
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @test_OpeningFcn, ...
'gui_OutputFcn', @test_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 test is made visible.
function test_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 test (see VARARGIN)
% Choose default command line output for test
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes test wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = test_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 mouse press over figure background, over a disabled or
% --- inactive control, or over an axes background.
function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x1 y1;
currPt = get(gca, 'CurrentPoint');
x = currPt(1,1);
y = currPt(1,2);
m=get(gca,'Xlim');
xmax=m(2);
n=get(gca,'Ylim');
ymax=n(2);
if(x<=xmax&&y<ymax)
% line(x, y,'marker','*');
line(x, y,'marker','o','MarkerFaceColor','r');
x1=[x1 x];
y1=[y1 y];
num = size(x1,2);
set(handles.number,'string',num2str(num));
end
% --- Executes on mouse motion over figure - except title and menu.
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
currPt = get(gca, 'CurrentPoint');
x = currPt(1,1);
y = currPt(1,2);
%line(x, y,'marker','*');
set(handles.y,'string',num2str(y));
set(handles.x,'string',num2str(x));
function x_Callback(hObject, eventdata, handles)
% hObject handle to x (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of x as text
% str2double(get(hObject,'String')) returns contents of x as a double
% --- Executes during object creation, after setting all properties.
function x_CreateFcn(hObject, eventdata, handles)
% hObject handle to x (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function y_Callback(hObject, eventdata, handles)
% hObject handle to y (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of y as text
% str2double(get(hObject,'String')) returns contents of y as a double
% --- Executes during object creation, after setting all properties.
function y_CreateFcn(hObject, eventdata, handles)
% hObject handle to y (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in kmeans_bt.
function kmeans_bt_Callback(hObject, eventdata, handles) %%%上次写的是Kmeans函数 这次没改
% hObject handle to kmeans_bt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x1 y1
n = size(x1,2);
% for test=1:n
% line(x1(test),y1(test),'marker','*','Color',[1 1 1]);
% end
x=zeros(n,2);
for i=1:n
x(i,1)=x1(i);
x(i,2)=y1(i);
end
T = get(handles.T,'String');
t=str2double(T);
%[mx,sx,t,p] = EMCluster(x,t);
[ pai Yz mu E ] = GMM_function( x,t);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% hold on;
cla reset;
for i=1:n
line(x(i,1), x(i,2),'marker','o','MarkerFaceColor','r');
end
axis([0 10 0 10]);
hold on;
for i=1:t
% line(5, 5,'marker','o','MarkerFaceColor','b');
[x y]=meshgrid(linspace(0,10,80)',linspace(0,10,80)');
X=[x(:) y(:)];
z=mvnpdf(X,mu(:,i)',E(:,:,i));
contour(x,y,reshape(z,80,80));
end
% figure(2); %%%%%%%%%%%%%%%%%%%%%画图 可以把用三维的方式把高斯函数画出来 这里注释掉了 需要的自己改一下就行了
% for i=1:t
% [x y]=meshgrid(linspace(0,10,80)',linspace(0,10,80)');
% Z=[x(:) y(:)];
% z=mvnpdf(Z,mu(:,i)',E(:,:,i));
% surf(x,y,reshape(z,80,80));
% hold on;
% end
% nn=0;
% for i=1:t
% figure(2+i);
% nn=2+i;
% [x y]=meshgrid(linspace(0,10,80)',linspace(0,10,80)');
% X=[x(:) y(:)];
% z=mvnpdf(X,mu(:,i)',E(:,:,i));
% surf(x,y,reshape(z,80,80));
% hold on;
% end
% for i=1:t
% figure(nn+1);
% [x y]=meshgrid(linspace(0,10,80)',linspace(0,10,80)');
% X=[x(:) y(:)];
% z=mvnpdf(X,mu(:,i)',E(:,:,i));
% contour(x,y,reshape(z,80,80));
% hold on;
% end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over kmeans_bt.
function kmeans_bt_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to kmeans_bt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% means=zeros(20,30,2);%最多20个聚类 每个聚类最多50个点
% num_means=zeros(20);%每个聚类的点的个数
% m=0;%聚类的个数
% T = get(handles.T,'String');
% t=str2double(T);
% t
% 1
% set(handles.x,'string',num2str(33333));
% --- Executes during object creation, afte
- 1
- 2
前往页