📄 fmri_input_run_ui.m
字号:
end;
if (length(evt_onset) > 0) & isempty(onset_list)
errmsg = 'ERROR: Invalid input onsets';
set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
return;
end;
if (length(find(onset_list >= num_scans)) ~= 0),
errmsg = 'Cannot have an onset larger than the number of scans';
set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
return;
end;
curr_onsets{onset_idx} = onset_list;
setappdata(gcf,'CurrOnsets',curr_onsets);
if get(findobj('tag','ReplicateLabel'),'value')
run_info = getappdata(gcf,'SessionRunInfo');
SaveRunInfo(curr_run);
for i = 1:length(run_info)
LoadRunInfo(i);
setappdata(gcf,'CurrOnsets',curr_onsets);
SaveRunInfo(i);
end
ShowRunInfo(curr_run);
end
status = 1;
return; % EditOnsets
%----------------------------------------------------------------------------
function MoveSlider()
slider_hdl = findobj(gcf,'Tag','EventOnsetSlider');
curr_value = round(get(slider_hdl,'Value'));
total_rows = round(get(slider_hdl,'Max'));
top_onset_idx = total_rows - curr_value + 1;
setappdata(gcf,'TopOnsetIdx',top_onset_idx);
DisplayEventOnsets;
return; % MoveSlider
%----------------------------------------------------------------------------
function SetupSlider()
top_onset_idx = getappdata(gcf,'TopOnsetIdx');
rows = getappdata(gcf,'NumOnsetRows');
curr_onsets = getappdata(gcf,'CurrOnsets');
num_onset = length(curr_onsets);
total_rows = num_onset;
slider_hdl = findobj(gcf,'Tag','EventOnsetSlider');
if (total_rows > 1) % don't need to update when no condition
set(slider_hdl,'Min',1,'Max',total_rows, ...
'Value',total_rows-top_onset_idx+1, ...
'Sliderstep',[1/(total_rows-1)-0.00001 1/(total_rows-1)]);
end;
return; % UpdateSlider
%----------------------------------------------------------------------------
function ClearRunInfo()
run_info = getappdata(gcf,'SessionRunInfo');
conditions = getappdata(gcf,'SessionConditions');
curr_run = getappdata(gcf,'CurrRun');
total_runs = getappdata(gcf,'TotalRuns');
run_info(curr_run).num_scans = '';
run_info(curr_run).data_path = [];
run_info(curr_run).data_files = [];
run_info(curr_run).file_pattern = '*.img';
for j=1:length(conditions), run_info(curr_run).evt_onsets{j} = []; end;
setappdata(gcf,'SessionRunInfo',run_info);
LoadRunInfo(curr_run);
DisplayEventOnsets;
return; % ClearRunInfo
%----------------------------------------------------------------------------
function ShowRunInfo(run_idx)
curr_run = getappdata(gcf,'CurrRun');
total_runs = getappdata(gcf,'TotalRuns');
if (run_idx < 1) | (run_idx > total_runs)
errmsg = 'The run index is out of range';
set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
set(findobj(gcf,'Tag','NumRunEdit'),'String',num2str(curr_run));
return;
else
SaveRunInfo(curr_run);
end;
LoadRunInfo(run_idx);
DisplayEventOnsets;
return; % ShowRunInfo
%----------------------------------------------------------------------------
function DeleteRunInfo()
run_info = getappdata(gcf,'SessionRunInfo');
total_runs = getappdata(gcf,'TotalRuns');
curr_run = getappdata(gcf,'CurrRun');
if (total_runs == 1), % it is the only run
ClearRunInfo;
return;
end;
mask = zeros(1,total_runs);
mask(curr_run) = 1;
run_idx = find(mask == 0);
run_info = run_info(run_idx);
setappdata(gcf,'TotalRuns',total_runs-1);
setappdata(gcf,'SessionRunInfo',run_info);
if (curr_run == total_runs),
curr_run = curr_run - 1;
end;
LoadRunInfo(curr_run);
DisplayEventOnsets;
return; % DeleteRunInfo
%----------------------------------------------------------------------------
function EditDataDirectory
data_dir = get(gcbo,'String');
if (exist(data_dir,'dir') ~= 7)
msg = 'ERROR: Invalid directory.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
elseif (strcmp(data_dir,getappdata(gcf,'CurrDataPath')) == 1)
return; %directory has not been changed
else
% update the data directory, and clear the field of the data files
% after changing directory
%
h = findobj(gcf,'Tag','DataFileEdit');
curr_selected_files = get(h,'Userdata');
curr_selected_files{1} = data_dir;
curr_selected_files{2} = [];
set(h,'String','','Userdata',curr_selected_files);
setappdata(gcf,'CurrDataPath',data_dir);
setappdata(gcf,'CurrDataFiles',[]);
end;
return; % EditDataDirectory
%----------------------------------------------------------------------------
function num_str = Number2String(numbers)
if isempty(numbers),
num_str = '';
return;
end;
len = length(numbers);
num = numbers(:); % make sure it is a column vector;
tmp_str = strjust(num2str(num),'left');
num_str = deblank(tmp_str(1,:));
for i=2:len,
num_str = [num_str ' ' deblank(tmp_str(i,:))];
end;
return; % Number2String
%----------------------------------------------------------------------------
function delete_fig
try
load('pls_profile');
pls_profile = which('pls_profile.mat');
fmri_input_run_pos = get(gcbf,'position');
save(pls_profile, '-append', 'fmri_input_run_pos');
catch
end
try
plot_hrf_fig = getappdata(gcbf,'plot_hrf_fig');
close(plot_hrf_fig);
catch
end
try
plot_onset_fig = getappdata(gcbf,'plot_onset_fig');
close(plot_onset_fig);
catch
end
return;
%----------------------------------------------------------------------------
function status = is_same_across_run
status = 1;
run_info = getappdata(gcf,'SessionRunInfo');
for i = 2:length(run_info)
if ~isequal(run_info(1).evt_onsets, run_info(i).evt_onsets)
status = 0;
return;
end
end
return; % is_same_across_run
%----------------------------------------------------------------------------
function EditReplicate
replicate_status = get(findobj('tag','ReplicateLabel'),'value');
if replicate_status
run_info = getappdata(gcf,'SessionRunInfo');
curr_run = getappdata(gcf,'CurrRun');
for i = 1:length(run_info)
LoadRunInfo(i);
setappdata(gcf,'CurrOnsets',run_info(curr_run).evt_onsets);
SaveRunInfo(i);
end
ShowRunInfo(curr_run);
end
return; % EditReplicate
%----------------------------------------------------------------------------
function plot_hrf
CurrOnsets = getappdata(gcf,'CurrOnsets');
SessionConditions = getappdata(gcf,'SessionConditions');
NumConditions = length(SessionConditions);
h0 = gcf;
plot_hrf_fig_name = [];
try
plot_hrf_fig_name = get(getappdata(h0,'plot_hrf_fig'),'name');
catch
end
if ~isempty(plot_hrf_fig_name) & ...
strcmp(plot_hrf_fig_name,'Hemodynamic Response Function Plot')
msg = 'ERROR: HRF Plot window has already been opened.';
msgbox(msg,'ERROR','modal');
else
h01 = fmri_plot_hrf(SessionConditions, CurrOnsets);
if ~isempty(h01)
setappdata(h0,'plot_hrf_fig',h01);
end
end
return; % plot_hrf
%----------------------------------------------------------------------------
function plot_onset
CurrOnsets = getappdata(gcf,'CurrOnsets');
SessionConditions = getappdata(gcf,'SessionConditions');
h0 = gcf;
plot_onset_fig_name = [];
try
plot_onset_fig_name = get(getappdata(h0,'plot_onset_fig'),'name');
catch
end
if ~isempty(plot_onset_fig_name) & ...
strcmp(plot_onset_fig_name,'Onset Timing Plot')
msg = 'ERROR: Onset Timing Plot window has already been opened.';
msgbox(msg,'ERROR','modal');
else
h01 = fmri_plot_onset(SessionConditions, CurrOnsets);
if ~isempty(h01)
setappdata(h0,'plot_onset_fig',h01);
end
end
return; % plot_onset
%----------------------------------------------------------------------------
function result = check_run_ok
result=1;
run_info = getappdata(gcf,'SessionRunInfo');
for i=1:length(run_info)
curr_run = run_info(i);
if isempty(curr_run.data_path) | isempty(curr_run.data_files)
result=0;
errmsg = 'Data Directory and Data Files for all runs must be selected';
set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
end
for j=1:length(curr_run.evt_onsets)
if isempty(curr_run.evt_onsets{j})
result=0;
errmsg = 'All the Onsets field must be filled out';
set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
end
end
end
return;
%----------------------------------------------------------------------------
function LoadTxt
[fn, pn] = uigetfile('*.txt', 'Load Onsets for this run');
if isequal(fn, 0) | isequal(pn, 0)
return;
end;
onset_file = fullfile(pn, fn);
if ~CheckRunInfo
return;
end
slider_hdl = findobj(gcf,'Tag','EventOnsetSlider');
curr_value = round(get(slider_hdl,'Max'));
fid = fopen(onset_file, 'rt');
app = getappdata(gcf);
num_onset_disp = size(app.Onset_hlist,1);
remain_cond = length(app.SessionConditions);
breakwhile = 0;
while remain_cond > num_onset_disp
set(slider_hdl,'Value',curr_value);
MoveSlider;
for i=1:num_onset_disp
onset = fgetl(fid);
set(app.Onset_hlist(i,2), 'string', onset);
if ~EditOnsets(app.Onset_hlist(i,2))
breakwhile = 1;
break;
end
end
if breakwhile
break;
end
remain_cond = remain_cond - num_onset_disp;
curr_value = curr_value - num_onset_disp;
end
if remain_cond <= num_onset_disp
set(slider_hdl,'Value',curr_value);
MoveSlider;
for i=1:remain_cond
onset = fgetl(fid);
set(app.Onset_hlist(i,2), 'string', onset);
if ~EditOnsets(app.Onset_hlist(i,2))
break;
end
end
end
fclose(fid);
return;
%----------------------------------------------------------------------------
function SaveTxt
[fn, pn] = uiputfile('*.txt', 'Save Onsets for this run');
if isequal(fn, 0) | isequal(pn, 0)
return;
end;
onset_file = fullfile(pn, fn);
if ~CheckRunInfo
return;
end
slider_hdl = findobj(gcf,'Tag','EventOnsetSlider');
curr_value = round(get(slider_hdl,'Max'));
fid = fopen(onset_file, 'wt');
app = getappdata(gcf);
num_onset_disp = size(app.Onset_hlist,1);
remain_cond = length(app.SessionConditions);
breakwhile = 0;
while remain_cond > num_onset_disp
set(slider_hdl,'Value',curr_value);
MoveSlider;
for i=1:num_onset_disp
onset = get(app.Onset_hlist(i,2), 'string');
fprintf(fid, '%s\n', onset);
end
remain_cond = remain_cond - num_onset_disp;
curr_value = curr_value - num_onset_disp;
end
if remain_cond <= num_onset_disp
set(slider_hdl,'Value',curr_value);
MoveSlider;
for i=1:remain_cond
onset = get(app.Onset_hlist(i,2), 'string');
fprintf(fid, '%s\n', onset);
end
end
fclose(fid);
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -