📄 bfm_create_datamat_ui.m
字号:
elseif STOptions.MergeDataAcrossRuns & STOptions.SingleSubject
sess = load(session_file);
if STOptions.NumBehavior == num_cond * length(sess.session_info.run(1).blk_onsets{1})
num_behav_not_match = 0;
else
num_behav_not_match = num_cond * length(sess.session_info.run(1).blk_onsets{1});
end
elseif ~STOptions.MergeDataAcrossRuns & STOptions.SingleSubject
sess = load(session_file);
total_onset = 0;
for i = 1:sess.session_info.num_runs
total_onset = total_onset + length(sess.session_info.run(i).blk_onsets{1});
end
if STOptions.NumBehavior == num_cond * total_onset
num_behav_not_match = 0;
else
num_behav_not_match = num_cond * total_onset;
end
end
if num_behav_not_match
msg = ['ERROR: Rows of behavior data file should be ' num2str(num_behav_not_match)];
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
end
status = 1;
setappdata(gcf,'STOptions',STOptions);
return; % SaveDatamatOptions
%----------------------------------------------------------------------------
function RunGenDatamat(),
if exist('plslog.m','file')
plslog('Create BfMRI Datamat');
end
options = getappdata(gcf,'STOptions');
session_file = getappdata(gcf,'SessionFile');
orient = getappdata(gcf,'orient');
num_runs = getappdata(gcf,'NumRuns');
if options.SingleSubject
load(session_file);
old = [];
for r = 1:session_info.num_runs
if ~options.MergeDataAcrossRuns
old = [];
end
for c = 1:session_info.num_conditions0
tmp = session_info.run(r).blk_onsets{c};
tmp = tmp(find(tmp>=options.NumScansSkipped));
new = length(tmp);
if ~isempty(old) & ~isequal(old, new)
msg = 'Number of onsets must be the same.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
old = new;
end
end
end
% to make progress bar in the center
% progress_hdl = rri_progress_status(gcf,'Create','Creating Datamat');
fig1 = gcf;
progress_hdl = rri_progress_status('Create','Creating Datamat');
close(fig1);
run_idx = options.RunsIncluded;
% generate datamat for each run
%
% progress_factor = 1 / length(run_idx) * 0.6;
% setappdata(progress_hdl,'ProgressScale',progress_factor);
% for i=run_idx,
i = run_idx;
% curr_progress = (i-1)*progress_factor;
% setappdata(progress_hdl,'ProgressStart',curr_progress);
if (options.UseBrainRegionFile == 1)
% fmri_gen_datamat(session_file,i,options.BrainRegionFile, ...
bfm_get_datamat(session_file,i,options.BrainRegionFile, ...
options.MaxStdDev, ...
options.SliceIgnored, ...
options.NormalizeVolumeMean, ...
options.NumScansSkipped, ...
options.MergeDataAcrossRuns, ...
options.BehavData, ...
options.BehavName, ...
options.session_win_hdl, ...
options.NormalizeSignalMean, ...
options.ConsiderAllVoxels, ...
options.SingleSubject, ...
orient);
else
% fmri_gen_datamat(session_file,i,options.Threshold, ...
bfm_get_datamat(session_file,i,options.Threshold, ...
options.MaxStdDev, ...
options.SliceIgnored, ...
options.NormalizeVolumeMean, ...
options.NumScansSkipped, ...
options.MergeDataAcrossRuns, ...
options.BehavData, ...
options.BehavName, ...
options.session_win_hdl, ...
options.NormalizeSignalMean, ...
options.ConsiderAllVoxels, ...
options.SingleSubject, ...
orient);
end
% end;
return; % RunGenDatamat
% determine the common brain region from all runs
%
progress_factor = 1 / (length(run_idx)+1) * 0.4;
setappdata(progress_hdl,'ProgressScale',progress_factor);
setappdata(progress_hdl,'ProgressStart',0.6);
rri_progress_status(progress_hdl,'Show_message', ...
'Determine the common brain region ...');
coords_info = fmri_combine_coords(session_file,run_idx);
rri_progress_status(progress_hdl,'Update_bar',1);
% prepare clear up the datamat
% this block is moved up, because there is a possibility that
% datamat_prefix was changed during saving
%
load(session_file);
pls_data_path = session_info.pls_data_path;
datamat_prefix = session_info.datamat_prefix;
% generate the datamat
%
progress_factor = 1 / (length(run_idx)+3) * 0.4;
setappdata(progress_hdl,'ProgressStart',progress_factor+0.6);
bfm_gen_blk_datamat(session_file, options.NumScansSkipped, ...
options.RunsIncluded, coords_info, ...
options.MergeDataAcrossRuns, ...
options.BehavData, ...
options.BehavName);
% clear up the datamat
%
for i=run_idx,
datamat_file = sprintf('%s_run%d.mat',datamat_prefix,i);
datamat_file = fullfile(pls_data_path,datamat_file);
% rm_command = sprintf('rm %s',datamat_file);
% unix(rm_command);
try
eval(['delete ', datamat_file]);
catch
end
end;
return; % RunGenDatamat
% --------------------------------------------------------------------
function delete_fig
try
load('pls_profile');
pls_profile = which('pls_profile.mat');
bfm_create_datamat_pos = get(gcbf,'position');
save(pls_profile, '-append', 'bfm_create_datamat_pos');
catch
end
return;
%----------------------------------------------------------------------------
function SelectBehavData
[filename,pathname]=uigetfile('*.*','Select Behavior Data File');
if isequal(filename,0) | isequal(pathname,0) % Cancel was clicked
return;
end;
behavdata_file = [pathname, filename];
try
behavdata = load(behavdata_file);
catch % cannot open file
msg = ['ERROR: Could not open file'];
msgbox(msg,'ERROR','modal');
return;
end
setappdata(gcf,'BehavData',behavdata);
setappdata(gcf,'NumBehavior',size(behavdata, 1));
set(findobj(gcf,'Tag','NumberBehaviorEdit'),'String',size(behavdata,1));
return; % SelectBehavData
%----------------------------------------------------------------------------
function EditBehavData_all
session_file = getappdata(gcbf,'SessionFile');
load(session_file);
if isfield(session_info, 'behavname_all')
behavname = session_info.behavname_all;
behavdata = session_info.behavdata_all;
else
behavname = {};
behavdata = [];
end
[newbehavdata, newbehavname] = rri_edit_behav(num2str(behavdata), behavname, 'Edit Behavior Data');
if isequal(str2num(newbehavdata),behavdata) & isequal(newbehavname,behavname)
return;
else
answer = questdlg('Do you want to update session file with new behavior data?');
if ~strcmpi(answer,'yes')
return;
end
end
behavdata = newbehavdata;
behavname = newbehavname;
setappdata(gcf,'BehavData',str2num(behavdata));
setappdata(gcf,'BehavName',behavname);
setappdata(gcf,'NumBehavior',size(str2num(behavdata), 1));
set(findobj(gcf,'Tag','NumberBehaviorEdit'),'String',size(str2num(behavdata),1));
session_info.behavname_all = behavname;
session_info.behavdata_all = str2num(behavdata);
save(session_file, '-append', 'session_info');
return;
%----------------------------------------------------------------------------
function EditBehavData_each
session_file = getappdata(gcbf,'SessionFile');
load(session_file);
if isfield(session_info, 'behavname_each')
behavname = session_info.behavname_each;
behavdata = session_info.behavdata_each;
else
behavname = {};
behavdata = [];
end
[newbehavdata, newbehavname] = rri_edit_behav(num2str(behavdata), behavname, 'Edit Behavior Data');
if isequal(str2num(newbehavdata),behavdata) & isequal(newbehavname,behavname)
return;
else
answer = questdlg('Do you want to update session file with new behavior data?');
if ~strcmpi(answer,'yes')
return;
end
end
behavdata = newbehavdata;
behavname = newbehavname;
setappdata(gcf,'BehavData',str2num(behavdata));
setappdata(gcf,'BehavName',behavname);
setappdata(gcf,'NumBehavior',size(str2num(behavdata), 1));
set(findobj(gcf,'Tag','NumberBehaviorEdit'),'String',size(str2num(behavdata),1));
session_info.behavname_each = behavname;
session_info.behavdata_each = str2num(behavdata);
save(session_file, '-append', 'session_info');
return;
%----------------------------------------------------------------------------
function EditBehavData_all_single
session_file = getappdata(gcbf,'SessionFile');
load(session_file);
if isfield(session_info, 'behavname_all_single')
behavname = session_info.behavname_all_single;
behavdata = session_info.behavdata_all_single;
else
behavname = {};
behavdata = [];
end
[newbehavdata, newbehavname] = rri_edit_behav(num2str(behavdata), behavname, 'Edit Behavior Data');
if isequal(str2num(newbehavdata),behavdata) & isequal(newbehavname,behavname)
return;
else
answer = questdlg('Do you want to update session file with new behavior data?');
if ~strcmpi(answer,'yes')
return;
end
end
behavdata = newbehavdata;
behavname = newbehavname;
setappdata(gcf,'BehavData',str2num(behavdata));
setappdata(gcf,'BehavName',behavname);
setappdata(gcf,'NumBehavior',size(str2num(behavdata), 1));
set(findobj(gcf,'Tag','NumberBehaviorEdit'),'String',size(str2num(behavdata),1));
session_info.behavname_all_single = behavname;
session_info.behavdata_all_single = str2num(behavdata);
save(session_file, '-append', 'session_info');
return;
%----------------------------------------------------------------------------
function EditBehavData_each_single
session_file = getappdata(gcbf,'SessionFile');
load(session_file);
if isfield(session_info, 'behavname_each_single')
behavname = session_info.behavname_each_single;
behavdata = session_info.behavdata_each_single;
else
behavname = {};
behavdata = [];
end
[newbehavdata, newbehavname] = rri_edit_behav(num2str(behavdata), behavname, 'Edit Behavior Data');
if isequal(str2num(newbehavdata),behavdata) & isequal(newbehavname,behavname)
return;
else
answer = questdlg('Do you want to update session file with new behavior data?');
if ~strcmpi(answer,'yes')
return;
end
end
behavdata = newbehavdata;
behavname = newbehavname;
setappdata(gcf,'BehavData',str2num(behavdata));
setappdata(gcf,'BehavName',behavname);
setappdata(gcf,'NumBehavior',size(str2num(behavdata), 1));
set(findobj(gcf,'Tag','NumberBehaviorEdit'),'String',size(str2num(behavdata),1));
session_info.behavname_each_single = behavname;
session_info.behavdata_each_single = str2num(behavdata);
save(session_file, '-append', 'session_info');
return;
%----------------------------------------------------------------------------
function set_num_behav
session_file = getappdata(gcbf,'SessionFile');
load(session_file);
if get(findobj(gcf,'Tag','MergeDataAcrossRunsButton'),'Value') % all
if get(findobj(gcf,'Tag','SingleSubjectChkButton'),'Value')
if isfield(session_info, 'behavname_all_single')
behavname = session_info.behavname_all_single;
behavdata = session_info.behavdata_all_single;
else
behavname = {};
behavdata = [];
end
else
if isfield(session_info, 'behavname_all')
behavname = session_info.behavname_all;
behavdata = session_info.behavdata_all;
else
behavname = {};
behavdata = [];
end
end
else
if get(findobj(gcf,'Tag','SingleSubjectChkButton'),'Value')
if isfield(session_info, 'behavname_each_single')
behavname = session_info.behavname_each_single;
behavdata = session_info.behavdata_each_single;
else
behavname = {};
behavdata = [];
end
else % each
if isfield(session_info, 'behavname_each')
behavname = session_info.behavname_each;
behavdata = session_info.behavdata_each;
else
behavname = {};
behavdata = [];
end
end
end
setappdata(gcf,'BehavData',behavdata);
setappdata(gcf,'BehavName',behavname);
setappdata(gcf,'NumBehavior',size(behavdata, 1));
set(findobj(gcf,'Tag','NumberBehaviorEdit'),'String',size(behavdata,1));
return;
%----------------------------------------------------------------------------
function orient()
session_file = getappdata(gcf,'SessionFile');
orient = getappdata(gcf, 'orient');
if isempty(orient)
nii = [];
orient_pattern = [];
else
nii = orient.nii;
orient_pattern = orient.orient_pattern;
end
load(session_file);
datapath = session_info.run(1).data_path;
datafile = session_info.run(1).data_files{1};
imgfile = fullfile(datapath, datafile);
[dims, voxel_size, origin, nii, orient_pattern] = ...
rri_orient_pattern_ui(imgfile, nii, orient_pattern);
if isempty(nii)
return;
end
orient.dims = double(nii.hdr.dime.dim(2:4));
orient.voxel_size = double(nii.hdr.dime.pixdim(2:4));
orient.origin = double(nii.hdr.hist.originator(1:3));
orient.nii = nii;
orient.orient_pattern = orient_pattern;
setappdata(gcf, 'orient', orient);
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -