📄 erp_modify_datamat.m
字号:
function end_time_edit
time_info = getappdata(gcf, 'time_info');
prestim = time_info.prestim;
end_epoch = time_info.end_epoch;
digit_interval = time_info.digit_interval;
start_time = time_info.start_time;
end_time = time_info.end_time + digit_interval; % add 1 timepoint for display
end_time_hdl = getappdata(gcf,'end_time_hdl');
new_end_time = str2num(get(end_time_hdl,'string'));
if isempty(new_end_time) | new_end_time < digit_interval*2 ...
| new_end_time > end_epoch + digit_interval ...
| new_end_time <= start_time
msg = 'Invalid Analysis Ending Time';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
set(end_time_hdl,'string',num2str(end_time));
return;
end
% | mod(new_end_time-prestim, digit_interval)
if round(new_end_time/digit_interval)*digit_interval ~= new_end_time
new_end_time = round(new_end_time/digit_interval)*digit_interval;
set(end_time_hdl,'string',num2str(new_end_time));
end
new_end_time = new_end_time - digit_interval; % take out 1 timepoint
% which was for display
time_info.timepoint = round((new_end_time-start_time) / digit_interval + 1);
time_info.end_time = new_end_time;
setappdata(gcf,'time_info', time_info);
return; % end_time_edit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% click_modify
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function click_modify
chan_lst_hdl = getappdata(gcf,'chan_lst_hdl');
selected_channels = getappdata(gcf,'selected_channels');
selected_channels = zeros(1,length(selected_channels));
selected_channels(get(chan_lst_hdl,'value')) = 1;
subj_lst_hdl = getappdata(gcf,'subj_lst_hdl');
% old_ is the one before modified
%
old_time_info = getappdata(gcf,'old_time_info');
old_selected_subjects = getappdata(gcf,'old_selected_subjects');
old_selected_channels = getappdata(gcf,'old_selected_channels');
old_chan_order = getappdata(gcf,'old_chan_order');
old_selected_conditions = getappdata(gcf,'selected_conditions');
old_selected_behav = getappdata(gcf,'selected_behav');
setting1 = getappdata(gcf,'setting1');
% final selected_subjects
%
selected_subjects = zeros(1,length(old_selected_subjects));
selected_subjects(get(subj_lst_hdl,'value')) = 1;
cond_lst_hdl = getappdata(gcf,'cond_lst_hdl');
% final selected_conditions
%
selected_conditions = zeros(1,length(old_selected_conditions));
selected_conditions(get(cond_lst_hdl,'value')) = 1;
behav_lst_hdl = getappdata(gcf,'behav_lst_hdl');
% final selected_behav
%
selected_behav = zeros(1,length(old_selected_behav));
selected_behav(get(behav_lst_hdl,'value')) = 1;
time_info = getappdata(gcf,'time_info');
calling_fig = getappdata(gcf,'calling_fig');
% remove any 0 in wave_selection & avg_selection
%
wave_selection = setting1.wave_selection;
avg_selection = setting1.avg_selection;
wave_selection(find(wave_selection==0)) = [];
avg_selection(find(avg_selection==0)) = [];
% selected_wave, before modify
%
old_idx = [];
for i=find(old_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
% 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);
% setting1.wave_selection = [0 setting1.wave_selection]; % always add 0 back
if isempty(setting1.wave_selection)
setting1.wave_selection = 1; % select first new subj.
end;
% selected_avg, before modify
%
old_idx = [];
for i=find(old_selected_conditions)
old_idx = [old_idx i];
end
% selected_avg, after modify
%
idx = [];
for i=find(selected_conditions)
idx = [idx i];
end
% calculate new available idx for avg_selection
%
[tmp new_available] = intersect(old_idx, idx);
selected_new_available = intersect(avg_selection, new_available);
[tmp setting1.avg_selection] = ...
intersect(new_available, selected_new_available);
setting1.avg_selection = [0 setting1.avg_selection]; % always add 0 back
chan_order = getappdata(gcf,'chan_order');
old_filename = getappdata(gcf,'old_filename');
filename = getappdata(gcf,'filename');
filepath = getappdata(gcf,'filepath');
datamat_file = fullfile(filepath, filename);
if isequal(selected_channels, old_selected_channels) & ...
isequal(selected_conditions, old_selected_conditions) & ...
isequal(selected_subjects, old_selected_subjects) & ...
isequal(selected_behav, old_selected_behav) & ...
isequal(filename, old_filename) & ...
isequal(time_info, old_time_info) & isequal(chan_order, old_chan_order)
close(gcf);
return;
end
if ~rri_chkfname(filename, 'ERP', 'datamat')
msg = 'File name must be ended with _ERPdatamat.mat';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
session_info = getappdata(gcf,'session_info');
session_info.chan_order = chan_order;
if isequal(filename, old_filename)
try
save(datamat_file, '-append', 'selected_channels', 'selected_subjects', ...
'selected_conditions', 'selected_behav', 'time_info', ...
'setting1', 'session_info');
catch
datamat_file = [];
msg1 = ['WARNING: Unable to write datamat file.'];
set(findobj(gcf,'Tag','MessageLine'),'String',msg1);
return;
end
else
session_file = getappdata(gcf,'session_file');
datafile = getappdata(gcf,'datafile');
create_ver = getappdata(gcf,'create_ver');
savfig = [];
if strcmpi(get(gcf,'windowstyle'),'modal')
savfig = gcf;
set(gcf,'windowstyle','normal');
end
% save datamat file
%
done = 0;
while ~done
try
save(datamat_file, 'datafile', 'create_ver', ...
'session_file', 'session_info', 'selected_behav', ...
'selected_conditions', 'selected_subjects', ...
'selected_channels', 'time_info', 'setting1');
done = 1;
catch
done1=0;
while ~done1
putfile_filter = datamat_file;
[filename, pathname] = uiputfile(putfile_filter, ...
'Can not save datamat file, please try again');
if isequal(filename,0)
datamat_file = [];
msg1 = ['WARNING: Datamat file is not saved.'];
%uiwait(msgbox(msg1,'Uncomplete','modal'));
set(findobj(gcf,'Tag','MessageLine'),'String',msg1);
done1=1;
return;
else
if rri_chkfname(filename, 'ERP', 'datamat')
datamat_file = fullfile(pathname, filename);
done1=1;
else
msg = ['File name must be ended with _ERPdatamat.mat'];
uiwait(msgbox(msg,'Wrong filename','modal'));
end
end
end
end
end
if ~isempty(savfig)
set(savfig,'windowstyle','modal');
end
end
close(gcf);
if ~isequal(filename, old_filename)
set(calling_fig, 'name', ['ERP Amplitude: ', datamat_file]);
end
erp_plot_ui({datamat_file, 1, calling_fig});
return; % click_modify
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% delete_fig
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function delete_fig
try
load('pls_profile');
pls_profile = which('pls_profile.mat');
erp_create_modify_pos = get(gcbf,'position');
save(pls_profile, '-append', 'erp_create_modify_pos');
catch
end
return;
%--------------------------------------------------------------------
function edit_chan_order
session_info = getappdata(gcf,'session_info');
chan_lst_hdl = getappdata(gcf,'chan_lst_hdl');
old_chan_order = getappdata(gcf,'old_chan_order');
chan_order = getappdata(gcf,'chan_order');
% chan_order is [] when create datamat
%
if isempty(old_chan_order)
old_chan_order = session_info.chan_order;
end
if isempty(chan_order)
chan_order = session_info.chan_order;
end
chan_order = ...
erp_select_chan(num2str(chan_order), session_info.system, 'Edit Channel Order', 0);
chan_order = str2num(chan_order);
if length(old_chan_order) ~= length(chan_order) | ...
length(chan_order) ~= length(unique(chan_order)) | ...
min(chan_order) < 1
msg = 'Invalid Channel Order';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
switch session_info.system.class
case 1
type_str = 'BESAThetaPhi|EGI128|EGI256';
switch session_info.system.type
case 1
load('erp_loc_besa148');
case 2
load('erp_loc_egi128');
case 3
load('erp_loc_egi256');
end
case 2
type_str = 'CTF-150';
switch session_info.system.type
case 1
load('erp_loc_ctf150');
end
end
chan_name = chan_nam(chan_order,:);
set(chan_lst_hdl, 'string', chan_name);
select_all_chan
setappdata(gcf,'chan_order',chan_order);
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -