📄 bfm_analysis_ui.m
字号:
% save handles for the group profiles
group_hdls = [g_h1, g_h2, g_h3, g_h4];
setappdata(h0,'Group_hlist',group_hdls);
group_template = copyobj(group_hdls,h0);
set(group_template,'visible','off','Tag','GroupUIControls');
setappdata(h0,'GroupTemplate',group_template);
group_h = 0.05;
setappdata(h0,'GroupHeight', group_h);
lower_h = 0.08; % vert. space for Number of groups etc.
setappdata(h0,'lower_h',lower_h);
setappdata(h0,'CurrGroupProfiles',[]);
setappdata(h0,'TopGroupIdx',1);
setappdata(h0,'full_path', 0);
setappdata(h0,'posthoc_data_file','');
setappdata(h0,'cond_selection',[]);
setappdata(h0,'bscan',[]);
setappdata(gcf,'behavname',{});
setappdata(gcf,'behavdata',[]);
setappdata(gcf,'behavdata_lst',{});
SetupGroupRows;
CreateAddRow;
DisplayGroupProfiles(0);
UpdateSlider;
return; % init
%----------------------------------------------------------------------------
function SetupGroupRows()
group_hdls = getappdata(gcf,'Group_hlist');
group_h = getappdata(gcf,'GroupHeight');
lower_h = getappdata(gcf,'lower_h');
bottom_pos = get(findobj(gcf,'Tag','GroupProfileFrame'),'Position');
top_pos = get(group_hdls(1,2),'Position');
rows = floor(( top_pos(2) - bottom_pos(2) - lower_h) / group_h + 1);
v_pos = top_pos(2) - [0:rows-1]*group_h;
group_template = getappdata(gcf,'GroupTemplate');
edit_cbf = '';
delete_cbf = 'bfm_analysis_ui(''DELETE_GROUP'');';
select_cbf = 'bfm_analysis_ui(''SELECT_GROUP'');';
nr = size(group_hdls,1);
if (rows < nr) % too many rows
for i=rows+1:nr,
delete(group_hdls(i,:));
end;
group_hdls = group_hdls(1:rows,:);
else % add new rows
for i=nr+1:rows,
new_g_hdls = copyobj(group_template,gcf);
group_hdls = [group_hdls; new_g_hdls'];
end;
end;
v = 'off';
for i=1:rows,
new_g_hdls = group_hdls(i,:);
pos = get(new_g_hdls(1),'Position'); pos(2) = v_pos(i)-0.01;
set(new_g_hdls(1),'String','','Position',pos,'Visible',v,'UserData',i);
pos = get(new_g_hdls(2),'Position'); pos(2) = v_pos(i);
set(new_g_hdls(2),'String','', 'Position',pos, 'Visible',v, ...
'UserData',i,'Callback',edit_cbf);
pos = get(new_g_hdls(3),'Position'); pos(2) = v_pos(i);
set(new_g_hdls(3),'String','Delete','Position',pos,'Visible',v, ...
'UserData',i,'Callback',delete_cbf);
pos = get(new_g_hdls(4),'Position'); pos(2) = v_pos(i);
set(new_g_hdls(4),'String','Edit','Position',pos,'Visible',v, ...
'UserData',i,'Callback',select_cbf);
end;
% setup slider position
%
slider_hdl = findobj(gcf,'Tag','GroupSlider');
s_pos = get(slider_hdl,'Position');
s_pos(2) = v_pos(end);
s_pos(4) = group_h * rows;
set(slider_hdl,'Position',s_pos);
setappdata(gcf,'Group_hlist',group_hdls);
setappdata(gcf,'NumRows',rows);
return; % SetupGroupRows
%----------------------------------------------------------------------------
function DisplayGroupProfiles(full_path)
curr_group_profiles = getappdata(gcf,'CurrGroupProfiles');
top_group_idx = getappdata(gcf,'TopGroupIdx');
group_hdls = getappdata(gcf,'Group_hlist');
rows = getappdata(gcf,'NumRows');
num_group = length(curr_group_profiles);
group_idx = top_group_idx;
last_row = 0;
for i=1:rows
g_hdls = group_hdls(i,:);
if (group_idx <= num_group),
curr_group_name = curr_group_profiles{group_idx}.short_name;
set(g_hdls(1),'String',sprintf('Group #%d.',group_idx),'Visible','on');
set(g_hdls(2),'String',sprintf('%s',curr_group_name), ...
'Enable', 'inactive', 'Visible','on');
set(g_hdls(3),'String','Delete','Enable','on','Visible','on');
set(g_hdls(4),'String','Edit','Enable','on','Visible','on');
group_idx = group_idx + 1;
last_row = i;
else
set(g_hdls(1),'String','','Visible','off');
set(g_hdls(2),'String','','Visible','off');
set(g_hdls(3),'String','Delete','Visible','off');
set(g_hdls(4),'String','Edit','Visible','off');
end;
end;
% display or hide the add row
%
if (last_row < rows)
row_idx = last_row+1;
g_hdls = group_hdls(row_idx,:);
pos = get(g_hdls(2),'Position');
ShowAddRow(group_idx,pos(2),row_idx);
else
HideAddRow;
end;
% display or hide the slider
%
if (top_group_idx ~= 1) | (last_row == rows)
ShowSlider;
else
HideSlider;
end;
return; % DisplayGroupProfiles
%----------------------------------------------------------------------------
function CreateAddRow()
group_template = getappdata(gcf,'GroupTemplate');
a_hdls = copyobj(group_template,gcf);
set(a_hdls(1),'String','','Foreground',[0.4 0.4 0.4],'Visible','off', ...
'UserData',1);
set(a_hdls(2),'String','','Enable','off','Background',[0.8 0.8 0.8], ...
'Visible','off');
set(a_hdls(3),'String','Add','Visible','off', ...
'Callback','bfm_analysis_ui(''ADD_GROUP'');');
set(a_hdls(4),'String','Edit','Visible','off','Enable','off');
setappdata(gcf,'AddRowHdls',a_hdls);
return; % CreateAddRow
%----------------------------------------------------------------------------
function ShowAddRow(group_idx,v_pos,row_idx)
a_hdls = getappdata(gcf,'AddRowHdls');
for j=1:length(a_hdls),
new_pos = get(a_hdls(j),'Position');
if j==1
new_pos(2) = v_pos-0.01;
else
new_pos(2) = v_pos;
end
set(a_hdls(j),'Position',new_pos);
set(a_hdls(j),'Visible','on');
end;
set(a_hdls(4),'Visible','Off');
set(a_hdls(2),'String','');
set(a_hdls(1),'String',sprintf('Group #%d.',group_idx),'UserData',row_idx);
return; % ShowAddRow
%----------------------------------------------------------------------------
function HideAddRow()
a_hdls = getappdata(gcf,'AddRowHdls');
for j=1:length(a_hdls),
set(a_hdls(j),'Visible','off');
end;
return; % HideAddRow
%----------------------------------------------------------------------------
function AddGroupProfiles()
rows = getappdata(gcf,'NumRows');
a_hdls = getappdata(gcf,'AddRowHdls');
curr_group_profiles = getappdata(gcf,'CurrGroupProfiles');
if ~isempty(curr_group_profiles) & ~isempty(curr_group_profiles{1}.name)
[profile_dir, g_files, g_ext] = fileparts(curr_group_profiles{1}.name{1});
else
curr = pwd;
if isempty(curr)
curr = filesep;
end
profile_dir = curr;
end;
group_idx = str2num(get(a_hdls(1),'String'));
new_group_profiles = fmri_select_profiles_ui(profile_dir,[]);
profiles_str = [];
for i=1:length(new_group_profiles),
[profile_dir, g_files, g_ext] = fileparts(new_group_profiles{i});
profiles_str = [profiles_str ' ' g_files];
end;
profiles_str = deblank(strjust(profiles_str,'left'));
cd(profile_dir);
if isempty(new_group_profiles) % CANCEL
return;
else
if isempty(getappdata(gcf,'cond_selection'))
tmp = load(new_group_profiles{1});
cond_selection = ones(1, tmp.session_info.num_conditions);
setappdata(gcf, 'cond_selection', cond_selection);
end
setappdata(gcf,'behavname',{});
setappdata(gcf,'behavdata',[]);
setappdata(gcf,'behavdata_lst',{});
end;
num_group = length(curr_group_profiles)+1;
curr_group_profiles{num_group}.short_name = profiles_str;
curr_group_profiles{num_group}.name = new_group_profiles;
setappdata(gcf,'CurrGroupProfiles',curr_group_profiles);
new_group_row = get(a_hdls(1),'UserData');
if (new_group_row == rows), % the new group row is the last row
top_group_idx = getappdata(gcf,'TopGroupIdx');
setappdata(gcf,'TopGroupIdx',top_group_idx+1);
end;
set(a_hdls(2),'String',profiles_str);
set(findobj(gcf,'Tag','NumberGroupEdit'),'String',num2str(num_group));
DisplayGroupProfiles;
if get(findobj(gcf,'Tag','SelectMean'),'Value')
% not a singl subject analysis
%
if (num_group > 1)
set(findobj(gcf,'Tag','GroupAnalysisRadiobutton'), ...
'Value',1,'Enable','inactive');
else
set(findobj(gcf,'Tag','GroupAnalysisRadiobutton'), ...
'Value',1,'Enable','on');
end
end;
UpdateSlider;
return; % AddGroupProfiles
%----------------------------------------------------------------------------
function SelectGroupProfiles(group_idx)
curr_group_profiles = getappdata(gcf,'CurrGroupProfiles');
group_hdls = getappdata(gcf,'Group_hlist');
row_idx = get(gcbo,'UserData');
group_id = get(group_hdls(row_idx,1),'String');
start_idx = findstr(group_id,'#')+1;
group_idx = str2num(group_id(start_idx:end-1));
if ~isempty(curr_group_profiles{1}.name)
[profile_dir, g_files, g_ext] = fileparts(curr_group_profiles{1}.name{1});
else
curr = pwd;
if isempty(curr)
curr = filesep;
end
profile_dir = curr;
end;
curr_profiles = curr_group_profiles{group_idx}.name;
new_group_profiles = fmri_select_profiles_ui(profile_dir,curr_profiles);
profiles_str = [];
for i=1:length(new_group_profiles),
[profile_dir, g_files, g_ext] = fileparts(new_group_profiles{i});
profiles_str = [profiles_str ' ' g_files];
end;
profiles_str = deblank(strjust(profiles_str,'left'));
cd(profile_dir);
if ~isempty(new_group_profiles)
curr_group_profiles{group_idx}.short_name = profiles_str;
curr_group_profiles{group_idx}.name = new_group_profiles;
setappdata(gcf,'CurrGroupProfiles',curr_group_profiles);
set(group_hdls(row_idx,2),'String',profiles_str);
tmp = load(new_group_profiles{1});
cond_selection = ones(1, tmp.session_info.num_conditions);
setappdata(gcf, 'cond_selection', cond_selection);
setappdata(gcf,'behavname',{});
setappdata(gcf,'behavdata',[]);
setappdata(gcf,'behavdata_lst',{});
end;
return; % SelectGroupProfiles
%----------------------------------------------------------------------------
function DeleteGroupProfiles()
curr_group_profiles = getappdata(gcf,'CurrGroupProfiles');
group_hdls = getappdata(gcf,'Group_hlist');
row_idx = get(gcbo,'UserData');
group_id = get(group_hdls(row_idx,1),'String');
start_idx = findstr(group_id,'#')+1;
group_idx = str2num(group_id(start_idx:end-1));
mask = ones(1,length(curr_group_profiles)); mask(group_idx) = 0;
idx = find(mask == 1);
curr_group_profiles = curr_group_profiles(idx);
num_group = length(curr_group_profiles);
set(findobj(gcf,'Tag','NumberGroupEdit'),'String',num2str(num_group));
setappdata(gcf,'CurrGroupProfiles',curr_group_profiles);
if get(findobj(gcf,'Tag','SelectMean'),'Value')
% not a singl subject analysis
%
if (num_group > 1)
set(findobj(gcf,'Tag','GroupAnalysisRadiobutton'), ...
'Value',1,'Enable','inactive');
else
set(findobj(gcf,'Tag','GroupAnalysisRadiobutton'), ...
'Value',1,'Enable','on');
end
end;
DisplayGroupProfiles;
UpdateSlider;
return; % DeleteGroupProfiles
%----------------------------------------------------------------------------
function UpdateGroupProfiles(group_idx)
curr_group = getappdata(gcf,'CurrGroupProfiles');
group_hdls = getappdata(gcf,'Group_hlist');
row_idx = get(gcbo,'UserData');
group_id = get(group_hdls(row_idx,1),'String');
start_idx = findstr(group_id,'#')+1;
group_idx = str2num(group_id(start_idx:end-1));
curr_group{group_idx}.short_name = get(gcbo,'String');
setappdata(gcf,'CurrGroupProfiles',curr_group);
return; % UpdateGroupProfiles
%----------------------------------------------------------------------------
function MoveSlider()
slider_hdl = findobj(gcf,'Tag','GroupSlider');
curr_value = round(get(slider_hdl,'Value'));
total_rows = round(get(slider_hdl,'Max'));
top_group_idx = total_rows - curr_value + 1;
setappdata(gcf,'TopGroupIdx',top_group_idx);
DisplayGroupProfiles;
return; % MoveSlider
%----------------------------------------------------------------------------
function UpdateSlider()
top_group_idx = getappdata(gcf,'TopGroupIdx');
rows = getappdata(gcf,'NumRows');
curr_group_profiles = getappdata(gcf,'CurrGroupProfiles');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -