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

📄 kmeanslayout.m

📁 常用ROBUST STATISTICAL
💻 M
字号:
function kmeanslayout
% This function will layout the gui controls. Eventually, this will be
% included in the complete function. Just have it now for simplicity.

% First get the user data from the root. See if anything is stored there.
% H.fig       Handle to GUI figure windwos
%
% H.data      Handle to popupmenu for data set to cluster. Might be reduced-dim data.
%             {'X'} or VARIES
% 
% H.plots     Handles to plots opened with this GUI.
%
% H.init      Handle to popupmenu for initialization method.
%             {'Sample observations','Uniform sample'}
% H.dist      Handle to popupmenu for distance to minimize with respect to
%             {'sqEuclidean';'cityblock'}
% H.plotyp      Handle to popupmenu for display of results.
%             {'ReClus';'Silhouette';'Graphical EDA'}
% H.k         Handle to popupmenu for number of clusters - k. Default is 2.
% H.trials    Handle to popupmenu for number of trials. Default is 5.

ud = get(0,'userdata');

H.fig = figure('Tag','kmeansgui',...
    'position',[150 150 726 524],...
    'resize','off',...
    'toolbar','none',...
    'menubar','none',...
    'numbertitle','off',...
    'name','K-Means Clustering GUI',...
    'CloseRequestFcn','kmeansgui(''close'')');

if strcmp(version('-release'),'14')
    set(0,'DefaultUicontrolFontname','Sans Serif');
end

H.plots = [];

if ~isempty(ud)
    % Then something is there already. Add necessary handles to the
    % structure. 
    ud.guis = [ud.guis(:); H.fig];
else
    % Set the usual stuff and save in root.
    ud = userdata;
    set(0,'userdata',ud)
end

%%%%%%%  FRAMES %%%%%%%%%%%%%%%
% set up all of the frames first.
uicontrol(H.fig, 'style','frame',...
    'position',[15 225 700 150]);

uicontrol(H.fig, 'style','frame',...
    'position',[15 30 275 180]);

uicontrol(H.fig,'style','frame',...
    'position',[300 30 415 180]);

%%%%%%% TEXT BOXES %%%%%%%%%%%%%%
% set up all of the text boxes
uicontrol(H.fig,'style','text',...
    'position',[200 485 300 27],...
    'fontweight','bold',...
    'fontsize',14,...
    'backgroundcolor',[.8 .8 .8],...
    'string','K-Means Clustering')

uicontrol(H.fig,'style','text',...
    'position',[45 375 650 44],...
    'horizontalalignment','left',...
    'backgroundcolor',[.8 .8 .8],...
    'string','You must specify the number of groups. The resulting clusters are dependent on the starting point, as well as the distance used. Thus, you might try different starting configurations. You can also run many trials (for the same configuration), and the best one will be returned.')

% title text
uicontrol(H.fig,'style','text',...
    'position',[40 330 170 20],...
    'fontsize',10,...
    'fontweight','bold',...
    'horizontalalignment','left',...
    'string','I. Create the Clusters')

uicontrol(H.fig,'style','text',...
    'position',[40 180 205 20],...
    'fontsize',10,...
    'fontweight','bold',...
    'horizontalalignment','left',...
    'string','II. Visualize the Clusters')

uicontrol(H.fig,'style','text',...
    'position',[330 180 230 20],...
    'fontsize',10,...
    'fontweight','bold',...
    'horizontalalignment','left',...
    'string','III. Output the Cluster IDs')

% Steps - text - Section I

uicontrol(H.fig,'style','text',...
    'position',[40 270 100 40],...
    'fontsize',9,...
    'horizontalalignment','left',...
    'string','1. Select data set:')

uicontrol(H.fig,'style','text',...
    'position',[145 270 100 40],...
    'fontsize',9,...
    'horizontalalignment','left',...
    'string','2. Choose initialization:')

uicontrol(H.fig,'style','text',...
    'position',[240 270 100 40],...
    'fontsize',9,...
    'horizontalalignment','left',...
    'string','3. Choose distance:')

uicontrol(H.fig,'style','text',...
    'position',[355 270 100 40],...
    'fontsize',9,...
    'horizontalalignment','left',...
    'string','4. Number of clusters-k:')

uicontrol(H.fig,'style','text',...
    'position',[450 270 100 40],...
    'fontsize',9,...
    'horizontalalignment','left',...
    'string','5. Number of trials:')


uicontrol(H.fig,'style','text',...
    'position',[570 270 100 40],...
    'fontsize',9,...
    'horizontalalignment','left',...
    'string','6. Push to cluster:')

% Text  - Section II:
uicontrol(H.fig,'style','text',...
    'position',[40 130 100 30],...
    'fontsize',9,...
    'horizontalalignment','left',...
    'string','Select plot type:')

uicontrol(H.fig,'style','text',...
    'position',[175 130 100 30],...
    'fontsize',9,...
    'horizontalalignment','left',...
    'string','Push to create plot:')


% Text  - Section III:
uicontrol(H.fig,'style','text',...
    'position',[355 130 182 21],...
    'fontsize',9,...
    'horizontalalignment','left',...
    'string','Push to output IDs:')

%%%%%%% BUTTONS  %%%%%%%%%%%%%%%%%%%%   
uicontrol(H.fig,'style','pushbutton',...
    'position',[14 491 170 23],...
    'string','LOAD DATA',...
    'tooltipstring','This will bring up the Load Data GUI',...
    'callback','loadgui')

uicontrol(H.fig,'style','pushbutton',...
    'position',[14 463 170 23],...
    'string','TRANSFORM',...
    'tooltipstring','This will bring up the Transform Data GUI.',...
    'callback','transformgui')

uicontrol(H.fig,'style','pushbutton',...
    'position',[14 434 170 23],...
    'string','DIMENSIONALITY REDUCTION',...
    'tooltipstring','This will bring up the Dimensionality Reduction GUI.',...
    'callback','dimredgui')

uicontrol(H.fig,'style','pushbutton',...
    'position',[570 245 100 25],...
    'string','DO CLUSTERING',...
    'tooltipstring','This will perform the clustering procedure. See the Command Window for progress.',...
    'callback','kmeansgui(''doclus'')')

uicontrol(H.fig,'style','pushbutton',...
    'position',[175 95 75 22],...
    'string','DO PLOT',...
    'tooltipstring','This will plot the data.',...
    'callback','kmeansgui(''doplot'')')

uicontrol(H.fig,'style','pushbutton',...
    'position',[330 105 150 25],...
    'string','OUTPUT CLUSTER IDs',...
    'tooltipstring','This will save an n-dimensional vector of cluster IDs to the workspace.',...
    'callback','kmeansgui(''cidsout'')')

% Close button
uicontrol(H.fig,'style','pushbutton',...
    'position',[620 485 66 25],...
    'string','CLOSE',...
    'callback','kmeansgui(''close'')',...
    'tooltipstring','Push this button to close the GUI window.')

%%%%%%%     POPUPMENUS %%%%%%%%%%%%%%%%%%%%%%%  

H.data = uicontrol('style','popupmenu',...
    'String',ud.dimred,...
    'position',[40 245 75 22],...
    'backgroundcolor','white');

H.init = uicontrol('style','popupmenu',...
    'String',{'Sample','Uniform'},...
    'position',[145 245 75 22],...
    'backgroundcolor','white',...
    'tooltipstring','First is to sample from observations; the second is to sample uniformly from the range of X.');

H.dist = uicontrol('style','popupmenu',...
    'String',{'sqEuclidean';'cityblock'},...
    'position',[240 245 90 22],...
    'backgroundcolor','white',...
    'tooltipstring','Distance that method should minimize with respect to.');

H.plotyp = uicontrol('style','popupmenu',...
    'String',{'ReClus';'Silhouette';'Graphical EDA'},...
    'position',[40 95 100 22],...
    'backgroundcolor','white');


%%%%%%      EDIT BOXES  %%%%%%%%%%%%%%%%%%%%%%
H.k = uicontrol('style','edit',...
    'string','2',...
    'position',[355 245 50 22],...
    'backgroundcolor','white');

H.trials = uicontrol('style','edit',...
    'string','5',...
    'position',[460 245 50 22],...
    'backgroundcolor','white',...
    'tooltipstring','Since this is dependent on the starting point, do several replications');


% Save Handles for THIS GUI in the UserData for this figure.
set(gcf,'userdata',H)

⌨️ 快捷键说明

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