0001 function vb_msrmnt_update_active_flag(base_file, active_ch, active_tr, new_file)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 if ~exist('base_file', 'var'), base_file = ''; end
0025 if ~exist('active_ch', 'var'), active_ch = []; end
0026 if ~exist('active_tr', 'var'), active_tr = []; end
0027 if ~exist('new_file', 'var'), new_file = ''; end
0028 [base_file, active_ch, active_tr, new_file] = ...
0029 inner_check_arguments(base_file, active_ch, active_tr, new_file);
0030
0031
0032
0033 info = vb_load_measurement_info(base_file);
0034 n_channel = vb_info_get_Nchannel(info);
0035 n_trial = vb_info_get_Nrepeat(info);
0036
0037 if ~isempty(active_ch)
0038 act_len = size(active_ch, 1);
0039 if act_len ~= n_channel
0040 warning('(%s)length of active_ch (%d) ~= n_channel(%d)\n', ...
0041 mfilename, act_len, n_channel);
0042 fprintf('(%s)ActiveChannel has not been updated\n', mfilename);
0043 else
0044 info = vb_info_set_active_channel(info, active_ch);
0045 end
0046 end
0047
0048 if ~isempty(active_tr)
0049 act_len = size(active_tr, 1);
0050 if act_len ~= n_trial
0051 warning('(%s)length of active_tr (%d) ~= n_trial(%d)\n', ...
0052 mfilename, act_len, n_trial);
0053 fprintf('(%s)ActiveTrial has not been updated\n', mfilename);
0054 else
0055 info = vb_info_set_active_trial(info, active_tr);
0056 end
0057 end
0058
0059
0060 if ~isempty(new_file)
0061 org_data = load(base_file);
0062 measurement = vb_info_get_measurement(info);
0063
0064 switch measurement
0065 case 'MEG'
0066 org_data.MEGinfo = info;
0067 case 'EEG'
0068 org_data.EEGinfo = info;
0069 otherwise
0070 error('(%s) unknown measurement : %s', mfilename, measurement);
0071 end
0072
0073 vb_save_struct(new_file, org_data);
0074
0075 end
0076
0077
0078
0079
0080
0081
0082
0083 function [base_file, active_ch, active_tr, new_file] = ...
0084 inner_check_arguments(base_file, active_ch, active_tr, new_file)
0085 func_ = mfilename;
0086
0087 if isempty(base_file)
0088 error('(%s) base_file is a required parameter', func_);
0089 end
0090
0091 if exist(base_file, 'file') ~= 2
0092 error('(%s) cannot find base_file : %s', func_, base_file);
0093 end
0094
0095 if isempty(active_ch)
0096
0097 end
0098
0099 if isempty(active_tr)
0100
0101 end
0102
0103 if isempty(new_file)
0104 new_file = base_file;
0105 end
0106 return;
0107
0108
0109
0110
0111
0112