📄 gedagui.m
字号:
function gedagui(arg)
% GEDAGUI Graphical Exploratory Data Analysis GUI
%
% This provides access to various graphical EDA methods. These include 2-D
% scatterplots, 3-D scatterplots, scatterplot matrices with brushing,
% Andrews' curves plots, and parallel coordinate plots.
%
% The GUI also provides access to the Brushing and Labeling GUI.
%
% One can call it from the edagui GUI or stand-alone from the command
% line. To call from the command line use
%
% gedagui
%
% Exploratory Data Analysis Toolbox, April 2005
% Martinez and Martinez, Exploratory Data Analysis with MATLAB
% CRC Press
% First set up the layout if it does not exist.
flg = findobj('tag','gedagui');
if isempty(flg)
% then create the gui
gedalayout
elseif nargin == 0
% bring it forward
figure(flg)
end
if nargin == 0
arg = ' ';
end
if strcmp(arg,'twodscatter')
twodscatter
elseif strcmp(arg,'threedscatter')
threedscatter
elseif strcmp(arg,'scattermat')
scattermat
elseif strcmp(arg,'brushlink')
brushlink
elseif strcmp(arg,'parallel')
doparallel
elseif strcmp(arg,'andrews')
doandrews
elseif strcmp(arg,'update')
update(gcf)
elseif strcmp(arg,'close')
% in other gui's we will do some housekeeping. With this gui, we do not
% have to do so. Obviously, the user will want to keep the data from
% the loadgui for other applications. That is the purpose.
tg = findobj('tag','gedagui');
H = get(tg,'userdata');
if ~isempty(H.plots)
button = questdlg('Closing this GUI will close the associated plot windows.',...
'Closing GUI Warning','OK','Cancel','Cancel');
if strcmp(button,'Cancel')
return
else
close(H.plots)
end
end
% If the brushgui is open, then it needs to be closed. This is only
% accessible through this GUI or the main edaGUI.
flg = findobj('tag','brushgui');
if ~isempty(flg)
close(flg)
end
% Now delete the gedagui
delete(tg)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function twodscatter
tg = findobj('tag','gedagui');
H = get(tg,'userdata');
ud = get(0,'userdata');
if isempty(ud.X)
errordlg('You must load some data first.')
return
end
% Get the dataset to be used.
tmp = get(H.data,'string');
dataset = tmp{get(H.data,'value')};
switch dataset
case 'X'
% use the original data data
data = ud.X;
xstr = 'X';
case 'PCA'
% use PCA field. this is the projection matrix so data =
% data*ud.pca(:,1:d).
% CHANGED THE FOLLOWING ON 11-6-05. JUST PROVIDE ALL 4 DIMENSIONS
% FOR PCA. THE USER CAN THEN PLOT WHICH ONES THEY WANT.
data = ud.X*ud.pca;
xstr = 'PCA';
case 'LLE'
data = ud.LLE;
xstr = 'LLE';
case 'HLLE'
data = ud.hLLE;
xstr = 'HLLE';
case 'ISOMAP'
% Check to see what is saved there. Might be the whole thing or
% might be just what the user outputs. Depends on whether the other
% gui is open or not.
% if iscell - then get the right number of dimensions wanted - like
% pca. else it is double - correct array to just use.
% CHANGED THIS ON 11-6-05. JUST SAVE THE MAXIMUM NUMBER OF
% DIMENSIOns.
[n,p] = size(ud.X);
if ~iscell(ud.isomap)
data = ud.isomap;
else
data = ud.isomap{end}';
end
xstr = 'ISOMAP';
case 'MDS'
% Added 11-12-05 - Process the MDS data.
data = ud.mds;
xstr = 'MDS';
case 'CMDS'
% Added 11-12-05 - Process the CMDS data.
data = ud.cmds;
xstr = 'CMDS';
case 'PPEDA'
% Added 11-12-05 - Process the PPEDA data.
Z = sphere(ud.X);
data = Z*ud.ppeda;
xstr = 'PPEDA';
end
[n,p] = size(data);
% Get the information for plotting: Dimensions to use.
tmp = get(H.dim2D,'string');
eval(['dim2d = [' tmp '];']);
dim2d = round(dim2d);
if length(dim2d) ~= 2
errordlg('Must enter two dimensions to plot.')
return
end
if any(dim2d < 1) | any(dim2d > p)
errordlg(['Dimensions must be between 1 and ' int2str(p)])
return
end
if dim2d(1) == dim2d(2)
errordlg('Dimensions must be different.')
return
end
% Get the color by groups flag.
colflag = get(H.popmode,'value');
% OK to plot
hf = figure;
set(hf,'tag','2D','numbertitle','off','name','EDA: 2-D Scatterplot','visible','off')
% Upon figure close, this should delete from the array.
set(hf,'CloseRequestFcn',...
'gedagui(''update'');tg = findobj(''tag'',''gedagui''); H = get(tg,''userdata''); H.plots(find(H.plots == gcf)) = []; set(tg,''userdata'',H); delete(gcf)')
% Set up stuff for brushing.
set(hf,'RendererMode','manual',...
'backingstore','off',...
'renderer','painters',...
'DoubleBuffer','on');
H.plots = [H.plots, hf];
set(tg,'userdata',H)
% Will need to store the handle for this window in the proper field for
% brush/link.
% The following is used for brush/link purposes.
figure(hf)
fud = [];
switch colflag
case 1
% just do a plain plot
set(hf,'visible','on')
set(hf,'backingstore','off','renderer','painters','DoubleBuffer','on')
Hline = plot(data(:,dim2d(1)),data(:,dim2d(2)),'ko');
% This is for brushing/linking.
% Default color and 'undo' color is black!
% Non-highlighted data will have a tag of 'black'
set(Hline,'markersize',3,'marker','o','linestyle','none',...
'markerfacecolor','w',...
'tag','black')
% NOTE: one handle per line. Access color of individual points by
% the 'xdata' and 'ydata' indices.
% Put proper labels on there. Check to see if any are loaded.
% This next section added nov 5.
if strcmp(dataset,'X')
% Then we are plotting the regular data set. Just use the
% regular labels.
xlabel(ud.varlab{dim2d(1)},'handlevisibility','on')
ylabel(ud.varlab{dim2d(2)},'handlevisibility','on')
newstrg = [ud.varlab{dim2d(1)} ' vs ' ud.varlab{dim2d(2)}];
else
% Then we are plotting something else - PCA, etc.
xlabel([xstr ' ' int2str(dim2d(1))],'handlevisibility','on');
ylabel([xstr ' ' int2str(dim2d(2))],'handlevisibility','on');
% set up the string for the popupmenu
newstrg = [xstr int2str(dim2d(1)) xstr int2str(dim2d(2))];
end
% Set up in the information for the plot menu.
% See if the brushgui is open. Reset the popupmenu string
hbgui = findobj('tag','brushgui');
if ~isempty(ud.brushptr) & ~isempty(hbgui)
% tack on the plot to the open brushgui menu
Hud = get(hbgui,'userdata');
strg = get(Hud.popplot,'string');
if ~iscell(strg)
strg = [{strg};{newstrg}];
else
strg = [strg;{newstrg}];
end
set(Hud.popplot,'string',strg)
elseif ~isempty(hbgui)
% it must be 'none'
Hud = get(hbgui,'userdata');
set(Hud.popplot,'string',newstrg)
end
% This plot can be brushed (and linked).
% Linking will be taken care of by merging this with the others
% that are only linkable.
ud.brushptr = [ud.brushptr, hf];
ud.brush = [ud.brush, Hline];
% Save handles to highlighted axes in here.
ud.highlight = [ud.highlight,gca];
set(0,'userdata',ud)
axis manual
case 2
% Color by groups - must be loaded by the user. Not from
% clustering.
if isempty(ud.classlab)
errordlg('You must load some group labels.')
close(hf)
return
end
set(hf,'visible','on')
gscatter(data(:,dim2d(1)),data(:,dim2d(2)),ud.classlab);
% This next section added nov 5.
if strcmp(dataset,'X')
% Then we are plotting the regular data set. Just use the
% regular labels.
xlabel(ud.varlab{dim2d(1)},'handlevisibility','on')
ylabel(ud.varlab{dim2d(2)},'handlevisibility','on')
newstrg = [ud.varlab{dim2d(1)} ' vs ' ud.varlab{dim2d(2)}];
else
% Then we are plotting something else - PCA, etc.
xlabel([xstr ' ' int2str(dim2d(1))],'handlevisibility','on');
ylabel([xstr ' ' int2str(dim2d(2))],'handlevisibility','on');
% set up the string for the popupmenu
newstrg = [xstr int2str(dim2d(1)) xstr int2str(dim2d(2))];
end
case 3
% Color by clusters.
if isempty(ud.kmeansids) & isempty(ud.agcids) & isempty(ud.mbcids)
% haven't clustered anything yet.
errordlg('You must create some clusters first.')
close(hf)
return
end
menustrg = [];
cidstr = [];
if ~isempty(ud.kmeansids)
menustrg = [menustrg, {'k-Means Clusters'}];
cidstr = [cidstr, {'ud.kmeansids'}];
end
if ~isempty(ud.agcids)
menustrg = [menustrg, {'Agglomerative Clustering'}];
cidstr = [cidstr, {'ud.agcids'}];
end
if ~isempty(ud.mbcids)
menustrg = [menustrg, {'Model-Based Clustering'}];
cidstr = [cidstr, {'ud.mbcids'}];
end
if length(cidstr) == 1
% no need for a listbox. Just plot.
set(hf,'visible','on')
eval(['gscatter(data(:,dim2d(1)),data(:,dim2d(2)), ' cidstr{1} ' );'])
% Put proper labels on there. Check to see if any are loaded.
% This next section added nov 5.
if strcmp(dataset,'X')
% Then we are plotting the regular data set. Just use the
% regular labels.
xlabel(ud.varlab{dim2d(1)},'handlevisibility','on')
ylabel(ud.varlab{dim2d(2)},'handlevisibility','on')
newstrg = [ud.varlab{dim2d(1)} ' vs ' ud.varlab{dim2d(2)}];
else
% Then we are plotting something else - PCA, etc.
xlabel([xstr ' ' int2str(dim2d(1))],'handlevisibility','on');
ylabel([xstr ' ' int2str(dim2d(2))],'handlevisibility','on');
% set up the string for the popupmenu
newstrg = [xstr int2str(dim2d(1)) xstr int2str(dim2d(2))];
end
else
[sel,ok] = listdlg('PromptString','Select a type of clustering:',...
'SelectionMode','single',...
'ListString',menustrg);
if ok == 1
% person selected something.
set(hf,'visible','on')
eval(['gscatter(data(:,dim2d(1)),data(:,dim2d(2)), ' cidstr{sel} ' );'])
% Put proper labels on there. Check to see if any are loaded.
% This next section added nov 5.
if strcmp(dataset,'X')
% Then we are plotting the regular data set. Just use the
% regular labels.
xlabel(ud.varlab{dim2d(1)},'handlevisibility','on')
ylabel(ud.varlab{dim2d(2)},'handlevisibility','on')
newstrg = [ud.varlab{dim2d(1)} ' vs ' ud.varlab{dim2d(2)}];
else
% Then we are plotting something else - PCA, etc.
xlabel([xstr ' ' int2str(dim2d(1))],'handlevisibility','on');
ylabel([xstr ' ' int2str(dim2d(2))],'handlevisibility','on');
% set up the string for the popupmenu
newstrg = [xstr int2str(dim2d(1)) xstr int2str(dim2d(2))];
end
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function threedscatter
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -