0001 function [result] = vb_posfile_remake_eegfile(pos_file, eeg_file, 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
0025 if ~exist('pos_file', 'var'), pos_file = ''; end
0026 if ~exist('eeg_file', 'var'), eeg_file = ''; end
0027 if ~exist('new_file', 'var'), new_file = ''; end
0028 [pos_file, eeg_file, new_file, result] = ...
0029 inner_check_arguments(pos_file, eeg_file, new_file);
0030
0031 if result ~= 0
0032 return;
0033 end
0034
0035
0036
0037 cur_eeg = load(eeg_file);
0038
0039 pos_info = vb_posfile_get_posinfo(pos_file);
0040
0041
0042
0043
0044
0045
0046
0047
0048 eeg_info = vb_load_measurement_info(eeg_file);
0049
0050
0051 [eeg_idx, pos_idx] = ...
0052 vb_util_get_index(eeg_info.ChannelName, pos_info.ChannelLabel);
0053
0054
0055 n_channel = length(eeg_idx);
0056
0057 old_ch_name = {};
0058 new_ch_name = {};
0059 if isfield(eeg_info, 'ChannelName')
0060 old_ch_name = eeg_info.ChannelName;
0061 new_ch_name = old_ch_name(eeg_idx);
0062
0063 eeg_info.ChannelName = new_ch_name;
0064 end
0065
0066 old_ch_id = [];
0067 new_ch_id = [];
0068 if isfield(eeg_info, 'ChannelID')
0069 old_ch_id = eeg_info.ChannelID;
0070 new_ch_id = old_ch_id(eeg_idx);
0071 eeg_info.ChannelID = new_ch_id;
0072 end
0073
0074 if isfield(eeg_info, 'ChannelInfo')
0075 ch_info.Active = eeg_info.ChannelInfo.Active(eeg_idx);
0076 ch_info.Name = eeg_info.ChannelInfo.Name (eeg_idx);
0077 ch_info.ID = eeg_info.ChannelInfo.ID (eeg_idx);
0078 ch_info.Type = eeg_info.ChannelInfo.Type (eeg_idx);
0079
0080 eeg_info.ChannelInfo = ch_info;
0081 end
0082
0083 if isfield(eeg_info, 'ActiveChannel')
0084 active_channel = eeg_info.ActiveChannel(eeg_idx);
0085
0086 eeg_info.ActiveChannel = active_channel;
0087 end
0088
0089
0090 if isfield(eeg_info, 'ExtraChannelInfo')
0091 [ex_names, ex_idx] = vb_util_omit_list(old_ch_name, new_ch_name);
0092
0093 if ~isempty(ex_names)
0094 ex_names = vb_util_arrange_list(ex_names, 0);
0095
0096 n_ex_channel = length(ex_names);
0097 ex_info.Channel_active = ones(n_ex_channel,1);
0098 ex_info.Channel_name = ex_names;
0099 ex_info.Channel_type = ones(n_ex_channel,1);
0100 ex_info.Channel_id = old_ch_id(ex_idx);
0101
0102
0103 eeg_info.ExtraChannelInfo = ex_info;
0104 else
0105 fprintf('(%s) It may not be necessary to update ExtraChannelInfo\n', ...
0106 mfilename);
0107 end
0108 end
0109
0110
0111
0112 eeg_info = ...
0113 vb_eeginfo_set_sensor_position(eeg_info, pos_info.SensorPosition(pos_idx,:));
0114
0115
0116 [center, radius, c_type] = vb_posfile_get_sphericalinfo(pos_file);
0117 eeg_info.Vcenter = center;
0118 eeg_info.Vradius = radius;
0119 eeg_info.CoordType = c_type;
0120
0121
0122 eeg_info.MRI_ID = vb_posfile_load_mrikey(pos_file);
0123 eeg_info = vb_info_set_transinfo(eeg_info, vb_posfile_load_transinfo(pos_file));
0124
0125
0126 eeg_info.Nchannel = n_channel;
0127
0128 cur_eeg.EEGinfo = eeg_info;
0129
0130 vb_save_struct(new_file, cur_eeg);
0131 return;
0132
0133
0134
0135
0136
0137
0138
0139 function [pos_file, eeg_file, new_file, result] = ...
0140 inner_check_arguments(pos_file, eeg_file, new_file)
0141
0142 func_ = mfilename;
0143 result = 0;
0144
0145 if isempty(pos_file)
0146 fprintf('(%s) pos_file is a required parameter\n', func_);
0147 result = 1;
0148 return;
0149 end
0150
0151 if exist(pos_file, 'file') ~= 2
0152 fprintf('(%s) cannot find pos_file : %s\n', func_, pos_file);
0153 result = 1;
0154 return;
0155 end
0156
0157 if isempty(eeg_file)
0158 fprintf('(%s) eeg_file is a required parameter\n', func_);
0159 result = 2;
0160 return;
0161 end
0162
0163 if exist(eeg_file, 'file') ~= 2
0164 fprintf('(%s) cannot find eeg_file : %s\n', func_, eeg_file);
0165 result = 2;
0166 return;
0167 end
0168
0169 if isempty(new_file)
0170 new_file = eeg_file;
0171 end
0172 return;
0173
0174
0175
0176
0177
0178