📄 erp_plot_scores_ui.m
字号:
msgbox(msg,'ERROR','modal');
else
% It seems that Matlab has a lot of bugs in Legend function,
% Slow, not working after copyobj, etc. ...
%
if strcmp(get(axis_old,'userdata'),'PlotScalpDesignScores')
old_legend = getappdata(gcf,'LegendHdl');
if ~isempty(old_legend),
try
delete(old_legend{1});
catch
end;
end;
end;
if strcmp(get(axis_old,'userdata'),'PlotDesignScores')
old_legend = getappdata(gcf,'LegendHdl2');
if ~isempty(old_legend),
try
delete(old_legend{1});
catch
end;
end;
end;
if strcmp(get(axis_old,'userdata'),'PlotDesignLV')
old_legend = getappdata(gcf,'LegendHdl3');
if ~isempty(old_legend),
try
delete(old_legend{1});
catch
end;
end;
end;
h01 = erp_new_axis_ui;
set(h01,'name','Current Axis');
axis_new = gca;
conditions = getappdata(h0, 'conditions');
% redraw legend
%
if strcmp(get(axis_old,'userdata'),'PlotScalpDesignScores') ...
& ~isempty(conditions)
legend_state = get(findobj(h0,'Tag','LegendMenu'),'Userdata');
axes(axis_old);
[l_hdl, o_hdl] = legend(conditions, 0);
legend_txt(o_hdl);
set(l_hdl,'color',[0.9 1 0.9]);
setappdata(h0, 'LegendHdl',[{l_hdl} {o_hdl}]);
if (legend_state == 1),
DisplayLegend('on');
else
DisplayLegend('off');
end;
figure(h01)
axes(axis_new);
[l_hdl, o_hdl] = legend(conditions, 0);
legend_txt(o_hdl);
set(l_hdl,'color',[0.9 1 0.9]);
setappdata(h01, 'LegendHdl',[{l_hdl} {o_hdl}]);
if (legend_state == 1),
DisplayLegend('on');
else
DisplayLegend('off');
end;
end
if strcmp(get(axis_old,'userdata'),'PlotDesignScores') ...
& ~isempty(conditions)
legend_state = get(findobj(h0,'Tag','LegendMenu'),'Userdata');
axes(axis_old);
[l_hdl, o_hdl] = legend(conditions, 0);
legend_txt(o_hdl);
set(l_hdl,'color',[0.9 1 0.9]);
setappdata(h0, 'LegendHdl2',[{l_hdl} {o_hdl}]);
if (legend_state == 1),
DisplayLegend('on');
else
DisplayLegend('off');
end;
figure(h01)
axes(axis_new);
[l_hdl, o_hdl] = legend(conditions, 0);
legend_txt(o_hdl);
set(l_hdl,'color',[0.9 1 0.9]);
setappdata(h01, 'LegendHdl2',[{l_hdl} {o_hdl}]);
if (legend_state == 1),
DisplayLegend('on');
else
DisplayLegend('off');
end;
end
if strcmp(get(axis_old,'userdata'),'topPlotDesignLV') ...
& ~isempty(conditions)
legend_state = get(findobj(h0,'Tag','LegendMenu'),'Userdata');
axes(axis_old);
[l_hdl, o_hdl] = legend(conditions, 0);
legend_txt(o_hdl);
set(l_hdl,'color',[0.9 1 0.9]);
setappdata(h0, 'LegendHdl3',[{l_hdl} {o_hdl}]);
if (legend_state == 1),
DisplayLegend('on');
else
DisplayLegend('off');
end;
figure(h01)
axes(axis_new);
[l_hdl, o_hdl] = legend(conditions, 0);
legend_txt(o_hdl);
set(l_hdl,'color',[0.9 1 0.9]);
setappdata(h01, 'LegendHdl3',[{l_hdl} {o_hdl}]);
if (legend_state == 1),
DisplayLegend('on');
else
DisplayLegend('off');
end;
end
if ~isempty(h01)
setappdata(h0,'axis_fig',h01);
setappdata(h01,'main_fig',h0);
end
end
return; % view_axis
%-----------------------------------------------------------
function fig_bt_dn()
score_hdl = getappdata(gcf,'score_hdl');
for i=1:length(score_hdl(:))
set(score_hdl(i), 'selected', 'off'); % remove selection
end
try
txtbox_hdl = getappdata(gcf,'txtbox_hdl');
delete(txtbox_hdl); % clear rri_txtbox
catch
end
return; % fig_bt_dn
%-----------------------------------------------------------
function select_subj()
% don't do anything if we're supposed to be zooming
tmp = zoom(gcf,'getmode');
if (isequal(tmp,'in') | isequal(tmp,'on')), return; end
userdata = get(gco, 'userdata');
grp_idx = userdata(1);
subj_idx = userdata(2); % subj idx
score_hdl = getappdata(gcf,'score_hdl');
subj_name_lst = getappdata(gcf, 'subj_name_lst');
num_cond_lst = getappdata(gcf, 'num_cond_lst');
num_subj_lst = getappdata(gcf, 'num_subj_lst');
num_conds = num_cond_lst(grp_idx);
num_subjs = num_subj_lst(grp_idx);
subj_name = subj_name_lst{grp_idx};
% deselect other subj
%
for m=1:length(num_subj_lst) %grp
for n = 1:num_subj_lst(m) %n=1:num_subjs
for k=1:num_conds
set(score_hdl(m,n,k),'selected','off');
end
end
end
for k=1:num_conds
set(score_hdl(grp_idx,subj_idx,k),'selected','on'); % select only this subj
end
txtbox_hdl = rri_txtbox(gca, 'Subject Name', subj_name{subj_idx});
setappdata(gcf, 'txtbox_hdl', txtbox_hdl);
return; % select_subj
%-----------------------------------------------------------
function remove_subject
subj_select_lst = getappdata(gcf, 'subj_select_lst');
score_hdl = getappdata(gcf,'score_hdl');
num_cond_lst = getappdata(gcf, 'num_cond_lst');
num_subj_lst = getappdata(gcf, 'num_subj_lst');
num_grp = getappdata(gcf,'num_grp');
for g=1:num_grp
for k=1:num_cond_lst(g)
for n=1:num_subj_lst(g)
if strcmp(get(score_hdl(g,n,k),'selected'),'on')
set(score_hdl(g,n,k),'visible','off');
subj_select_lst{g}(n) = 0;
end
end
end
end
try
txtbox_hdl = getappdata(gcf,'txtbox_hdl');
delete(txtbox_hdl); % clear rri_txtbox
catch
end
setappdata(gcf, 'subj_select_lst', subj_select_lst);
return;
%-----------------------------------------------------------
function un_remove_subject
subj_select_lst = getappdata(gcf, 'subj_select_lst');
score_hdl = getappdata(gcf,'score_hdl');
for i = 1:length(subj_select_lst)
subj_select_lst{i}(:) = 1;
end
for i = 1:length(score_hdl)
set(score_hdl(:), 'visible','on');
end
setappdata(gcf, 'subj_select_lst', subj_select_lst);
return;
%-----------------------------------------------------------
function modify_datamat
datamat_files = getappdata(gcbf, 'datamat_files');
subj_select_lst = getappdata(gcbf, 'subj_select_lst');
old_subj_select_lst = getappdata(gcbf, 'old_subj_select_lst');
total_file_name = [];
for grp = 1:length(subj_select_lst)
if ~isequal(old_subj_select_lst{grp}, subj_select_lst{grp})
subj_select = subj_select_lst{grp};
file_name = datamat_files{grp};
try
load(file_name, 'setting1', ...
'selected_subjects', 'selected_conditions');
catch
msgbox(['Can not find datamat file ',file_name],'modal');
return;
end
old_selected_subjects = selected_subjects;
selected_subjects_idx = find(selected_subjects);
subj_select_idx = find(subj_select);
selected_subjects_idx = selected_subjects_idx(subj_select_idx);
selected_subjects = zeros(1,length(selected_subjects));
selected_subjects(selected_subjects_idx) = 1;
% selected_wave, before modify
%
old_idx = [];
for i=find(selected_conditions)
for j=find(old_selected_subjects)
old_idx = [old_idx (i-1)*length(old_selected_subjects) + j];
end
end
% selected_wave, after modify
%
idx = [];
for i=find(selected_conditions)
for j=find(selected_subjects)
idx = [idx (i-1)*length(selected_subjects) + j];
end
end
wave_selection = setting1.wave_selection;
wave_selection(find(wave_selection==0)) = [];
% calculate new available idx for wave_selection
%
[tmp new_available] = intersect(old_idx, idx);
selected_new_available = intersect(wave_selection, new_available);
[tmp setting1.wave_selection] = ...
intersect(new_available, selected_new_available);
save(file_name, '-append', 'selected_subjects', 'setting1');
[tmp file_name] = fileparts(file_name);
total_file_name = [total_file_name, ' ', file_name];
end
end
msgbox(['The following datamat file has been modified, please run PLS analysis again:', total_file_name],'modal');
return;
%------------------------------------------------
function toggle_dlv
hm_dlv = getappdata(gcf,'hm_dlv');
dlv_status = get(hm_dlv,'userdata');
if ~dlv_status % was not checked
set(hm_dlv, 'userdata',1, 'check','on');
view_dlv;
else
set(hm_dlv, 'userdata',0, 'check','off');
try
dlv_fig_user = get(getappdata(gcf,'dlv_fig'),'user');
if ~isempty(dlv_fig_user) & strcmp(dlv_fig_user,'LV Plot')
close(getappdata(gcf,'dlv_fig'));
end
catch
end
end
return; % toggle_dlv
%--------------------------------------------------
function view_dlv
h0 = gcf;
dlv_fig_user = [];
try
dlv_fig_user = get(getappdata(h0,'dlv_fig'),'user');
catch
end
lv_state = getappdata(gcbf,'CurrLVState');
lv_idx = find(lv_state == 1);
if ~isempty(dlv_fig_user) & strcmp(dlv_fig_user,'LV Plot') % update lv_idx
h01 = getappdata(h0,'dlv_fig');
figure(h01);
% msg = 'ERROR: Design LV Plot window has already been opened.';
% msgbox(msg,'ERROR','modal');
else
h01 = erp_plot_dlv_ui;
end
tit_fn = getappdata(gcbf,'tit_fn');
tit = ['Design LV Plot [', tit_fn, ']'];
set(h01,'name',tit);
s = getappdata(gcbf,'s');
cb = erp_per(s);
perm_result = getappdata(gcbf,'perm_result');
designlv = getappdata(gcbf,'designlv');
num_cond_lst = getappdata(gcbf, 'num_cond_lst');
num_subj_lst = getappdata(gcbf, 'num_subj_lst');
num_grp = length(num_subj_lst);
num_conds = num_cond_lst(1);
min_x = 0.5; max_x = size(designlv,1)+0.5;
min_y = min(designlv(:)); max_y = max(designlv(:));
margin_x = abs((max_x - min_x) / 20);
margin_y = abs((max_y - min_y) / 20);
% plot of the designlv
%
cla;hold on;
% the rows are stacked by groups. each group has several conditions.
% each condition could have several contrasts.
%
load('rri_color_code');
for g=1:num_grp
for k=1:num_conds
bar_hdl = bar((g-1)*num_conds+k, designlv((g-1)*num_conds+k,lv_idx));
set(bar_hdl,'facecolor',color_code(k,:));
end
end
hold off;
axis([min_x,max_x,min_y-margin_y,max_y+margin_y]);
set(gca,'tickdir','out','ticklength', [0.005 0.005], ...
'box','on');
ylabel('Design LV');
if isempty(perm_result)
title(sprintf('LV %d: %.2f%% crossblock', lv_idx, 100*cb(lv_idx)));
else
title(sprintf('LV %d: %.2f%% crossblock, p < %.3f', lv_idx, 100*cb(lv_idx), perm_result.sprob(lv_idx)));
end
% if(getappdata(gcbf, 'is_design_plot'))
% title('Weights of the contrasts for the Design LV');
% else
% title('Weights of the contrasts for the Behavior LV');
% end
grid on;
set(gca,'xtick',[1:num_grp]*num_conds - num_conds + 0.5);
set(gca,'xticklabel',1:num_grp);
conditions = getappdata(gcbf, 'conditions');
if ~isempty(conditions),
% remove the old legend to avoid the bug in the MATLAB5
old_legend = getappdata(gcbf,'LegendHdl3');
if ~isempty(old_legend),
try
delete(old_legend{1});
catch
end;
end;
% create a new legend, and save the handles
[l_hdl, o_hdl] = legend(conditions, 0);
legend_txt(o_hdl);
set(l_hdl,'color',[0.9 1 0.9]);
setappdata(gcbf,'LegendHdl3',[{l_hdl} {o_hdl}]);
legend_state = get(findobj(gcbf,'Tag','LegendMenu'),'Userdata');
if (legend_state == 1),
DisplayLegend('on');
else
DisplayLegend('off');
end;
else
setappdata(gcbf,'LegendHdl3',[]);
end;
xlabel('Groups');
if ~isempty(h01)
setappdata(h0,'dlv_fig',h01);
setappdata(h01,'main_fig',h0);
end
% end
return; % view_dlv
%---------------------------------------------------------------------------
function SelectLV(selected_lv)
lv_state = getappdata(gcf,'CurrLVState');
LV_hlist = getappdata(gcf,'LV_hlist');
top_lv = getappdata(gcf,'TopLVButton');
rows = getappdata(gcf,'NumLVRows');
bottom_lv = top_lv + rows - 1;
% remove the previous selection
%
prev_selected_lv = find(lv_state == 1);
if (prev_selected_lv >= top_lv & prev_selected_lv <= bottom_lv),
row_idx = prev_selected_lv - top_lv + 1;
set(LV_hlist(row_idx),'Value',0);
end;
UpdateLVButtonList = 0;
if ~exist('selected_lv','var') % select LV interactively
curr_row = get(gcbo,'Userdata');
curr_lv = top_lv + curr_row -1;
set(LV_hlist(curr_row),'Value',1);
else % select LV by specifying the index
curr_lv = selected_lv;
if (selected_lv >= top_lv & selected_lv <= bottom_lv),
row_idx = selected_lv - top_lv + 1;
set(LV_hlist(row_idx),'Value',1);
else
UpdateLVButtonList = 1;
end;
end;
lv_state = zeros(1,length(lv_state));
lv_state(curr_lv) = 1;
setappdata(gcf,'CurrLVState',lv_state);
if (UpdateLVButtonList)
SetTopLVButton(curr_lv);
end;
return; % SelectLV
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -