📄 fmri_input_run_ui.m
字号:
'Callback','fmri_input_run_ui(''DONE_BUTTON_PRESSED'');', ...
'Tag','DONEButton');
x = left_margin+.2;
w = .15;
pos = [x y w h];
c = uicontrol('Parent',h0, ... % CANCEL
'Units','normal', ...
'fontunit','normal', ...
'FontSize',fnt, ...
'Position',pos, ...
'String','CANCEL', ...
'Callback','fmri_input_run_ui(''CANCEL_BUTTON_PRESSED'');', ...
'Tag','CANCELButton');
x = .01;
y = 0;
w = 1;
pos = [x y w h];
c = uicontrol('Parent',h0, ... % MessageLine
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'ForegroundColor',[0.8 0.0 0.0], ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'Position',pos, ...
'String','', ...
'Tag','MessageLine');
h_file = uimenu('Parent',h0, ...
'Label', 'Edit', ...
'Tag', 'EditMenu');
m1 = uimenu(h_file, ...
'Label', 'Load Onsets from a text file for this run', ...
'Callback','fmri_input_run_ui(''LOAD_TXT'');', ...
'Tag', 'LoadTxtMenu');
m1 = uimenu(h_file, ...
'Label', 'Save Onsets to a text file for this run', ...
'Callback','fmri_input_run_ui(''SAVE_TXT'');', ...
'Tag', 'SaveTxtMenu');
m1 = uimenu(h_file, ...
'Label', 'Clear', ...
'separator', 'on', ...
'Callback','fmri_input_run_ui(''CLEAR_RUN'');', ...
'Tag', 'ClearRunsMenu');
m1 = uimenu(h_file, ...
'Label', 'Delete', ...
'Enable', 'on', ...
'Callback','fmri_input_run_ui(''DELETE_RUN'');', ...
'Tag', 'DeleteRunsMenu');
h_file = uimenu('Parent',h0, ...
'Label', 'Plot', ...
'Tag', 'PlotMenu');
m1 = uimenu(h_file, ...
'Label', 'HRF Plots in time points', ...
'Callback','fmri_input_run_ui(''PLOT_HRF'');', ...
'Tag', 'PlotHRFMenu');
m1 = uimenu(h_file, ...
'Label', 'Onset Timing Plot in seconds', ...
'Callback','fmri_input_run_ui(''PLOT_ONSET'');', ...
'Tag', 'PlotOnsetMenu');
curr = pwd;
if isempty(curr)
curr = filesep;
end
% set up the data directory
%
setappdata(gcf,'DataDirectory',curr);
onset_template = copyobj([t1 t2 t3],h0);
set(onset_template(1),'Tag','ConditionNameLabelTemplate','Visible','off');
set(onset_template(2),'Tag','EventOnsetEditTemplate','Visible','off');
set(onset_template(3),'Tag','EventOnsetLabelTemplate','Visible','off');
setappdata(gcf,'OnsetRowHeight',.12);
setappdata(gcf,'Onset_hlist',[t1 t2 t3]);
setappdata(gcf,'OnsetTemplate',onset_template);
setappdata(gcf,'TopOnsetIdx',1);
LoadSessionInfo(run_info,num_runs,conditions);
SetupEventOnsetRows;
DisplayEventOnsets;
SetupSlider;
return; % init
% --------------------------------------------------------------------
function SetupEventOnsetRows()
onset_hdls = getappdata(gcf,'Onset_hlist');
onset_template = getappdata(gcf,'OnsetTemplate');
row_height = getappdata(gcf,'OnsetRowHeight');
frame_pos = get(findobj(gcf,'Tag','EventOnsetFrame'),'Position');
clabel_pos = get(findobj(gcf,'Tag','ConditionNameLabel'),'Position');
top_frame_pos = frame_pos(2) + frame_pos(4);
margin = top_frame_pos - (clabel_pos(2) + clabel_pos(4));
rows = floor((frame_pos(4) - margin*2) / row_height);
v_pos = (top_frame_pos - margin) - [1:rows]*row_height;
nr = size(onset_hdls,1);
if (rows < nr) % too many rows
for i=rows+1:nr,
delete(onset_hdls(i,:));
end;
onset_hdls = onset_hdls(1:rows,:);
else % add more rows
for i=nr+1:rows,
new_s_hdls = copyobj(onset_template,gcf);
onset_hdls = [onset_hdls; new_s_hdls'];
end;
end;
first_onset_pos = get(onset_hdls(1,2),'Position');
width = first_onset_pos(3);
v = 'on';
for i=1:rows,
% Condition Label
new_s_hdls = onset_hdls(i,:);
pos = get(new_s_hdls(1),'Position'); pos(2) = v_pos(i)+0.05;
set(new_s_hdls(1),'String','','Position',pos,'Visible',v,'UserData',i);
% Onset Label
pos = get(new_s_hdls(3),'Position');
pos(2) = v_pos(i);
set(new_s_hdls(3),'Position',pos,'Visible',v,'UserData',i);
% Onsets
pos = get(new_s_hdls(2),'Position');
pos(2) = v_pos(i); pos(3) = width;
set(new_s_hdls(2),'String','','Position',pos,'Visible',v,'UserData',i);
end;
setappdata(gcf,'Onset_hlist',onset_hdls);
setappdata(gcf,'NumOnsetRows',rows);
return; % SetupEventOnsetRows
% --------------------------------------------------------------------
function DisplayEventOnsets()
cond = getappdata(gcf,'SessionConditions');
curr_onsets = getappdata(gcf,'CurrOnsets');
top_onset_idx = getappdata(gcf,'TopOnsetIdx');
onset_hdls = getappdata(gcf,'Onset_hlist');
rows = getappdata(gcf,'NumOnsetRows');
num_onsets = length(cond);
onset_idx = top_onset_idx;
for i=1:rows,
o_hdls = onset_hdls(i,:);
if (onset_idx <= num_onsets),
set(o_hdls(1),'String',cond{onset_idx},'Visible','on');
set(o_hdls(3),'String','Onsets:','Visible','on');
output_onset = Number2String(curr_onsets{onset_idx}); % edit
set(o_hdls(2),'String',output_onset,'Visible','on');
onset_idx = onset_idx + 1;
else
set(o_hdls(1),'String','','Visible','off');
set(o_hdls(2),'String','','Visible','off');
set(o_hdls(3),'String','','Visible','off');
end
end;
if (top_onset_idx ~= 1) | (num_onsets > rows)
set(findobj(gcf,'Tag','EventOnsetSlider'),'Visible','on');
else
set(findobj(gcf,'Tag','EventOnsetSlider'),'Visible','off');
end;
return; % DisplayEventOnsets
% --------------------------------------------------------------------
function LoadSessionInfo(run_info,total_runs,conditions)
setappdata(gcf,'SessionRunInfo',run_info);
if is_same_across_run
set(findobj('tag','ReplicateLabel'),'value',1);
if (length(run_info) < total_runs)
for i=(length(run_info)+1):total_runs
run_info(i).num_scans = '';
run_info(i).data_path = [];
run_info(i).data_files = [];
run_info(i).file_pattern = [];
if isfield(run_info(1), 'evt_onsets') & ~isempty(run_info(1).evt_onsets)
run_info(i).evt_onsets = run_info(1).evt_onsets;
else
for j=1:length(conditions)
run_info(i).evt_onsets{j} = [];
end;
end
end;
end;
else
set(findobj('tag','ReplicateLabel'),'value',0);
if (length(run_info) < total_runs)
for i=(length(run_info)+1):total_runs
run_info(i).num_scans = '';
run_info(i).data_path = [];
run_info(i).data_files = [];
run_info(i).file_pattern = [];
for j=1:length(conditions)
run_info(i).evt_onsets{j} = [];
end;
end;
end;
end
setappdata(gcf,'SessionConditions',conditions);
setappdata(gcf,'SessionRunInfo',run_info);
setappdata(gcf,'TotalRuns',total_runs);
LoadRunInfo(1);
return; % LoadSessionInfo
% --------------------------------------------------------------------
function LoadRunInfo(run_idx)
run_info = getappdata(gcf,'SessionRunInfo');
total_runs = getappdata(gcf,'TotalRuns');
if (run_idx == total_runs)
set(findobj(gcf,'Tag','NEXTButton'),'Enable','off');
else
set(findobj(gcf,'Tag','NEXTButton'),'Enable','on');
end;
set(findobj(gcf,'Tag','RunIndex'),'String',sprintf('Run #%d',run_idx));
if (run_idx == 1);
set(findobj(gcf,'Tag','PREVIOUSButton'),'Enable','off');
else
set(findobj(gcf,'Tag','PREVIOUSButton'),'Enable','on');
end;
curr_num_scans = run_info(run_idx).num_scans;
curr_data_path = run_info(run_idx).data_path;
curr_data_files = run_info(run_idx).data_files;
curr_file_pattern = run_info(run_idx).file_pattern;
curr_onsets = run_info(run_idx).evt_onsets;
if get(findobj('tag','ReplicateLabel'),'value')
curr_onsets = run_info(1).evt_onsets;
end
% ------- set up the field values ------------------------------------
%
% assume the number of scans same as previous run when it is empty
if isempty(curr_num_scans) & (run_idx > 1)
curr_num_scans = run_info(run_idx-1).num_scans;
end
set(findobj(gcf,'Tag','NumScansEdit'),'String',num2str(curr_num_scans));
fname = [];
for i=1:length(curr_data_files),
fname = [fname ' ' curr_data_files{i}];
end;
set(findobj(gcf,'Tag','DataDirectoryEdit'),'String',curr_data_path);
data_info = { curr_data_path, curr_data_files, curr_file_pattern };
set(findobj(gcf,'Tag','DataFileEdit'),'String',fname, ...
'Userdata',data_info);
set(findobj(gcf,'Tag','NumRunEdit'),'String',num2str(run_idx));
setappdata(gcf,'CurrRun',run_idx);
setappdata(gcf,'CurrNumScans',curr_num_scans);
setappdata(gcf,'CurrDataPath',curr_data_path);
setappdata(gcf,'CurrDataFiles',curr_data_files);
setappdata(gcf,'CurrDataPattern',curr_file_pattern);
setappdata(gcf,'CurrOnsets',curr_onsets);
return; % LoadRunInfo
% --------------------------------------------------------------------
function is_ok = CheckRunInfo
data_path = getappdata(gcf,'CurrDataPath');
data_files = getappdata(gcf,'CurrDataFiles');
if isempty(data_path) | isempty(data_files)
errmsg = 'ERROR: Data Directory and Data Files must be selected';
set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
is_ok = 0;
return;
end
is_ok = 1;
return; % CheckRunInfo
% --------------------------------------------------------------------
function SaveRunInfo(run_idx)
run_info = getappdata(gcf,'SessionRunInfo');
run_info(run_idx).num_scans = getappdata(gcf,'CurrNumScans');
run_info(run_idx).data_path = getappdata(gcf,'CurrDataPath');
run_info(run_idx).data_files = getappdata(gcf,'CurrDataFiles');
run_info(run_idx).file_pattern = getappdata(gcf,'CurrDataPattern');
run_info(run_idx).evt_onsets = getappdata(gcf,'CurrOnsets');
setappdata(gcf,'SessionRunInfo',run_info);
return; % SaveRunInfo
%----------------------------------------------------------------------------
function SelectDataFile
old_pointer = get(gcf,'Pointer');
set(gcf,'Pointer','watch');
h = findobj(gcf,'Tag','DataFileEdit');
previous_selected_files = get(h,'Userdata');
if isempty(previous_selected_files{1}),
data_path = getappdata(gcf,'DataDirectory');
curr_files = [];
fpattern = getappdata(gcf,'FilterPattern');
if isempty(fpattern), fpattern = '*.img'; end;
else
data_path = previous_selected_files{1};
curr_files = previous_selected_files{2};
fpattern = previous_selected_files{3};
if isempty(fpattern), fpattern = '*.img'; end;
end;
fig_title = 'Select Data Files';
[num_scans, selected_path, selected_files, filter_pattern] = ...
fmri_getfiles(fig_title,data_path,fpattern,curr_files);
if ~isempty(selected_files),
num_files = length(selected_files);
if (num_scans ~= getappdata(gcf,'CurrNumScans')),
errmsg = 'ERROR: The # of selected scans does not match the # of scans';
set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
else
img_files = [];
for i=1:num_files,
img_files = [img_files ' ' selected_files{i}];
end;
set(h,'String',img_files);
set(h,'Userdata',{selected_path, selected_files, filter_pattern});
setappdata(gcf,'CurrDataPath', selected_path);
setappdata(gcf,'CurrDataFiles', selected_files);
setappdata(gcf,'CurrDataPattern', filter_pattern);
h = findobj(gcf,'Tag','DataDirectoryEdit');
set(h,'String',selected_path,'TooltipString',selected_path);
data_path = fileparts(selected_path);
setappdata(gcf,'DataDirectory',data_path);
setappdata(gcf,'FilterPattern',filter_pattern);
end;
end;
set(gcf,'Pointer',old_pointer);
return; % SelectDataFile
%----------------------------------------------------------------------------
function SaveButtonPressed()
return; % SaveButtonPressed
%----------------------------------------------------------------------------
function EditNumScans()
num_scans = str2num(get(findobj(gcf,'Tag','NumScansEdit'),'String'));
if isempty(num_scans) | (length(num_scans) > 1),
errmsg = 'The input of number of scans is invalid';
set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
return;
end;
setappdata(gcf,'CurrNumScans',num_scans);
return; % EditNumScans
%----------------------------------------------------------------------------
function status = EditOnsets(h_onset)
status = 0;
if ~exist('h_onset', 'var')
h_onset = gcbo;
end
num_scans = str2num(get(findobj(gcf,'Tag','NumScansEdit'),'String'));
if isempty(num_scans),
errmsg = 'ERROR: Number of scans must be specified first';
set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
return;
end;
curr_run = getappdata(gcf,'CurrRun');
curr_onsets = getappdata(gcf,'CurrOnsets');
top_onset_idx = getappdata(gcf,'TopOnsetIdx');
row_idx = get(h_onset,'Userdata');
onset_idx = top_onset_idx + row_idx - 1;
evt_onset = deblank(strjust(get(h_onset,'String'),'left'));
% evaluate the matlab statement if the first character is '@'
% '@@' - last matlab statement
%
if ~isempty(evt_onset) & (evt_onset(1) == '@') % matlab statement
cmd_str = evt_onset(2:end);
if isequal(cmd_str,'@'), % display the last matlab statement
cmd_str = getappdata(gcf,'LastCommand');
set(h_onset,'String', cmd_str);
return;
else
setappdata(gcf,'LastCommand',evt_onset);
cmd_str = strrep(cmd_str,'{run#}',num2str(curr_run));
cmd_str = strrep(cmd_str,'{cond#}',num2str(onset_idx));
onset_list = eval(cmd_str,'[]')';
if isempty(onset_list),
errmsg = 'ERROR: Invalid MATLAB statement to generate the onsets.';
set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
end;
end;
set(h_onset,'String', Number2String(onset_list));
else
onset_list = str2num(evt_onset)';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -