0001 function [position, direction, coil_weight, center, channel_info] = ...
0002 vb_megfile_get_sensor_position_by_name(megfile, ch_name, active_swt)
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 if ~exist('megfile', 'var'), megfile = []; end
0045 if ~exist('ch_name', 'var'), ch_name = ''; end
0046 if ~exist('active_swt', 'var'), active_swt = []; end
0047 [megfile, ch_name, active_swt] = ...
0048 inner_check_arguments(megfile, ch_name, active_swt);
0049
0050
0051
0052 channel_info = [];
0053 meg_info = vb_megfile_load_meginfo(megfile);
0054 ch_info_cur = vb_load_channel_info(megfile, 'USER', ch_name);
0055
0056
0057 ch_info_meg = vb_load_channel_info(megfile, 'MEG');
0058 if isempty(ch_info_meg)
0059 active_swt = false;
0060 end
0061
0062 if active_swt
0063 active_idx = find(ch_info_meg.Active == true);
0064 base_names = ch_info_meg.Name(active_idx, :);
0065 else
0066 base_names = ch_info_meg.Name;
0067 end
0068
0069 base_idx = vb_util_get_matching_label_index(base_names, ch_info_cur.Name);
0070
0071 if ~isempty(base_idx)
0072 target_idx = base_idx;
0073
0074 load(megfile, 'pick', 'Qpick');
0075 c_weight = vb_meginfo_get_sensor_weight_meg(meg_info);
0076
0077 target_coil_idx = find(sum(abs(c_weight(target_idx, :)), 1) > 0);
0078
0079 pick_meg = pick(target_coil_idx, :);
0080 Qpick_meg = Qpick(target_coil_idx, :);
0081 c_weight_meg = c_weight(target_idx, target_coil_idx);
0082
0083 channel_info.Active = ch_info_meg.Active(target_idx);
0084 channel_info.Name = ch_info_meg.Name(target_idx);
0085 channel_info.Type = ch_info_meg.Type(target_idx);
0086 channel_info.ID = ch_info_meg.ID(target_idx);
0087 else
0088 pick_meg = [];
0089 Qpick_meg = [];
0090 c_weight_meg = [];
0091 end
0092
0093
0094 pick_ref = [];
0095 Qpick_ref = [];
0096 c_weight_ref = [];
0097
0098 ch_info_ref = vb_load_channel_info(megfile, 'REFERENCE');
0099 if ~isempty(ch_info_ref) && size(ch_info_ref.Name, 1)>0
0100
0101 if active_swt
0102 active_idx = find(ch_info_ref.Active == true);
0103 base_names = ch_info_ref.Name(active_idx, :);
0104 else
0105 base_names = ch_info_ref.Name;
0106 end
0107
0108 base_idx = vb_util_get_matching_label_index(base_names, ch_info_cur.Name);
0109
0110 if ~isempty(base_idx)
0111 target_idx = base_idx;
0112
0113 load(meg_file, 'ref_pick', 'ref_Qpick');
0114 pick_ref = ref_pick;
0115 Qpick_ref = ref_Qpick;
0116 c_weight_ref = vb_meginfo_get_sensor_weight_refmg(meg_info);
0117
0118 target_coil_idx = find(sum(abs(c_weight_ref(target_idx, :)), 1) > 0);
0119
0120 pick_ref = pick_ref(target_coil_idx, :);
0121 Qpick_ref = Qpick_ref(target_coil_idx, :);
0122 c_weight_ref = c_weight_ref(target_idx, target_coil_idx);
0123 end
0124 end
0125
0126
0127 position = [pick_meg; pick_ref];
0128 direction = [Qpick_meg; Qpick_ref];
0129
0130 len_meg_ch = size(c_weight_meg, 1);
0131 len_meg_cl = size(c_weight_meg, 2);
0132 len_ref_ch = size(c_weight_ref, 1);
0133 len_ref_cl = size(c_weight_ref, 2);
0134
0135 len_ch = len_meg_ch + len_ref_ch;
0136 len_coil = len_meg_cl + len_ref_cl;
0137 coil_weight = zeros(len_ch, len_coil);
0138
0139
0140 coil_weight(1:len_meg_ch, 1:len_meg_cl) = c_weight_meg;
0141
0142
0143 coil_weight((len_meg_ch+1):len_ch, (len_meg_cl+1):len_coil) = c_weight_ref;
0144
0145
0146 center = [];
0147 if isfield(meg_info, 'Vcenter')
0148 center = meg_info.Vcenter;
0149 end
0150
0151 return;
0152
0153
0154
0155
0156
0157
0158
0159 function [megfile, ch_name, active_swt] = ...
0160 inner_check_arguments(megfile, ch_name, active_swt)
0161 func_ = mfilename;
0162
0163 if isempty(megfile)
0164 error('(%s) MEG-MAT file is a required parameter', func_);
0165 end
0166
0167 if exist(megfile, 'file') ~= 2
0168 error('(%s)cannot find MEG-MAT file : %s', megfile);
0169 end
0170
0171 [Measurement] = vb_load_device(megfile);
0172
0173 if ~strcmpi(Measurement, 'MEG')
0174 error('(%s)this file is not MEG file : %s', func_, megfile);
0175 end
0176
0177 if ~iscell(ch_name)
0178 ch_name = {ch_name};
0179 end
0180
0181 if isempty(ch_name{1})
0182 ch_info = vb_load_channel_info(megfile, 'MEG');
0183 ch_name = ch_info.Name;
0184 end
0185
0186 if isempty(active_swt)
0187 active_swt = false;
0188 end
0189 return;
0190
0191
0192
0193
0194
0195