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

📄 brushgui.m

📁 常用ROBUST STATISTICAL
💻 M
📖 第 1 页 / 共 2 页
字号:
function brushgui(arg)
% BRUSHGUI Brushing and Labeling GUI
%
% This GUI function allows one to brush plots and see the corresponding 
% plots highlighted in the other open plots. These plots must be called
% from the EDA GUIs.
%
% Brushable plots: 2-D scatterplot, ReClus, rectangle plot
% Linkable plots: brushable plots, Andrews' curves, parallel coordinates,
%                   3-D scatterplot, scatterplot matrix.
%
%   Exploratory Data Analysis Toolbox, April 2005
%   Martinez and Martinez, Exploratory Data Analysis with MATLAB
%   CRC Press

% Find out if the gedagui is open. The only way they can brush and link is
% if that gui is open. If not, provide an error message.
Hgeda = findobj('tag','gedagui');
if isempty(Hgeda)
    errordlg('The Graphical EDA GUI must be open to brush and link plots.')
    return
end

% First set up the layout if it does not exist.
flg = findobj('tag','brushgui');
if isempty(flg)
    % then create the gui
    brushlayout
end

if nargin == 0
    arg = ' ';
end
if strcmp(arg,'brushplot')
    % Execute button from brush frame
    H = get(flg,'userdata');
    if ~isempty(H.Hbrush)
        resetplots
    end
    brushplot
    
elseif strcmp(arg,'createbrush')
    H = get(flg,'userdata');
    CreateBrushButtDwn(H,flg)
    
elseif strcmp(arg,'BrushButtDwn')
    % User has clicked on the brush.
    % Set the function for brush motion.
    set(gcf,'WindowButtonMotionFcn','brushgui(''movebrush'')')
    % Set the function for when the user clicks up on the brush.
    set(gcf,'WindowButtonUpFcn','brushgui(''movebrushbuttup'')')
    set(gcf,'Pointer','fleur');
    
elseif strcmp(arg,'movebrush')
    % When brush moves - call update function.   
    MoveBrush
    
elseif strcmp(arg,'movebrushbuttup')
    % User finished moving the brush - let up on the button.
    % Reset the windows functions.
    movebrushbuttup

elseif strcmp(arg,'reset')
    % This resets all plots to their original color. 
    % used with all frames
    resetplots
    
elseif strcmp(arg,'delbrush')
    % This deletes the brush.
    % Gets rid of the brush handles, etc.
    delbrush
    
elseif strcmp(arg,'color')
    % This returns the chosen color for all frames. 
    H = get(flg,'userdata');
    % Note that if the user hits the cancel button, then the value in the
    % field is 0. Use this for error checking.
    tmp = uisetcolor('Choose the color:')
    if length(tmp) ~= 1
        H.color = tmp;
    end
    set(flg,'userdata',H)
    
elseif strcmp(arg,'groupcolor')
    % This one colors the selected group with the selected color.
    H = get(flg,'userdata');
    if ~isempty(H.Hbrush)    
        resetplots    
    end
    groupcolor(H);
    
elseif strcmp(arg,'obscolor')
    % This one colors the selected observation with the chosen color.
    H = get(flg,'userdata');
    if ~isempty(H.Hbrush) 
        resetplots
    end
    obscolor(H)
        
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','brushgui');
    H = get(tg,'userdata');
    ud = get(0,'userdata');
    resetplots
    movebrushbuttup
    Haxs = get(ud.brushptr,'children');
    for i = 1:length(Haxs)
        if iscell(Haxs)
            set(Haxs{i},'buttondown','')
        else
            set(Haxs(i),'buttondown','')
        end
    end
    delete(tg)
    
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function brushplot
% This brings up the selected plot to brush.
ud = get(0,'userdata');
if isempty(ud.X)
    errordlg('You must load up some data and plot first.')
    return
end
if isempty(ud.brushptr)
    errordlg('You must have some plots open to brush.')
    return
end
tg = findobj('tag','brushgui');
H = get(tg,'userdata'); % userdata for this gui.
% Reset everything - including the buttondown function for axes
resetplots
Haxs = get(ud.brushptr,'children');
for i = 1:length(Haxs)
    if iscell(Haxs)
        set(Haxs{i},'buttondown','')
    else
        set(Haxs(i),'buttondown','')
    end
end
% Get the brush mode: 1 = transient, 2 = lasting.
mode = get(H.popmode,'value');
if mode == 1
    H.mode = 'transient';
elseif mode == 2
    H.mode = 'lasting';
else
    H.mode = 'undo';    % this un-highlights individual points.
end
% Get the plot to brush. This SHOULD be index to the brush pointer.
bplot = get(H.popplot,'value');
figure(ud.brushptr(bplot))
Hax = get(ud.brushptr(bplot),'children');
% This figure is made active. ONLY this plot has the ability to draw a
% brush.
set(Hax,'buttondown','brushgui(''createbrush'')','drawmode','fast')
% Reset the handle to the current brushable plot.
H.brushplot = ud.brushptr(bplot);
set(tg,'userdata',H)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function resetplots
% Reset all plots to their original color - black
Hgui = findobj('tag','brushgui');
H = get(Hgui,'userdata');
ud = get(0,'userdata');
hndls = findobj('tag','high');
delete(hndls)

% for ii = 1:length(ud.highlight)
%     set(ud.highlight(ii),'xdata',nan,'ydata',nan)
% end
set(ud.linkap,'color','k')
% % delete the brush
delbrush

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function delbrush
Hgui = findobj('tag','brushgui');
H = get(Hgui,'userdata');
ud = get(0,'userdata');
if ~isempty(H.Hbrush) & ishandle(H.Hbrush)
    delete(H.Hbrush);
end
H.Hbrush = [];
set(Hgui,'userdata',H)
movebrushbuttup


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function groupcolor(H)
% This is executed when the person clicks on 'execute' button for Color the
% Groups.
% H is the structure to the brushgui userdata

ud = get(0,'userdata');
% Find the group that has been selected.
grpstrg = get(H.listgroup,'string'); 
grp = get(H.listgroup,'value');
if strcmp(grpstrg(grp),'None')
    errordlg('You must load up some class labels first.')
    return
end
% H.color, ud.classlab
% Find the indices to the observations belonging to the selected group.
if iscell(grpstrg)
    tmp = str2num(grpstrg{grp});
else
    tmp = str2num(grpstrg(grp));
end
inds = find(ud.classlab == tmp);
% Color the groups in the brushable plots
for ii = 1:length(ud.highlight)
    axes(ud.highlight(ii));
    % First get the data that are plotted there.
    Hline = findobj(ud.highlight(ii),'tag','black');
    Xp = get(Hline,'xdata');   % This is the full data set.
    Yp = get(Hline,'ydata');
    % Now color the group.
    Ht = line('xdata',Xp(inds),'ydata',Yp(inds),...
        'markersize',3,'marker','o','linestyle','none',...
        'tag','high',...
        'markerfacecolor',H.color);     % Placeholder for highlighted points. 
    set(Ht,'parent',ud.highlight(ii));
    
end
if ~isempty(ud.linkap)
    % set these to the right color.
    set(ud.linkap(inds,:),'color',H.color);
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function obscolor(H)
% This is executed when the person clicks on 'execute' button for Color the
% Observations.
% H is the structure to the brushgui userdata
ud = get(0,'userdata');
% Find the observations that have been selected. 
obs = get(H.listcase,'value');
% Color the obs in the brushable plots
for ii = 1:length(ud.highlight)
    axes(ud.highlight(ii));
    % First get the data that are plotted there.
    Hline = findobj(ud.highlight(ii),'tag','black');
    Xp = get(Hline,'xdata');   % This is the full data set.
    Yp = get(Hline,'ydata');
    % Now color the group.
    Ht = line('xdata',Xp(obs),'ydata',Yp(obs),...
        'markersize',3,'marker','o','linestyle','none',...
        'tag','high',...
        'markerfacecolor',H.color);     % Placeholder for highlighted points. 
    set(Ht,'parent',ud.highlight(ii));
    
end
if ~isempty(ud.linkap)
    % set these to the right color.
    set(ud.linkap(obs,:),'color',H.color);
end




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%     CreateBrushButtDwn  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

⌨️ 快捷键说明

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