0001 function [position, direction, coil_weight, center] = ...
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 if ~exist('megfile', 'var'), megfile = []; end
0038 if ~exist('ch_name', 'var'), ch_name = ''; end
0039 if ~exist('active_swt', 'var'), active_swt = []; end
0040 [megfile, ch_name, active_swt] = ...
0041 inner_check_arguments(megfile, ch_name, active_swt);
0042
0043
0044
0045 meg_info = vb_megfile_load_meginfo(megfile);
0046 ch_info_cur = vb_load_channel_info(megfile, 'USER', ch_name);
0047
0048
0049 ch_info_meg = vb_load_channel_info(megfile, 'MEG');
0050 if isempty(ch_info_meg)
0051 active_swt = false;
0052 end
0053
0054 if active_swt
0055 active_idx = find(ch_info_meg.Active == true);
0056 base_names = ch_info_meg.Name(active_idx, :);
0057 else
0058 base_names = ch_info_meg.Name;
0059 end
0060
0061 base_idx = vb_util_get_matching_label_index(base_names, ch_info_cur.Name);
0062
0063 if ~isempty(base_idx)
0064 target_idx = base_idx;
0065
0066 [pick, Qpick] = vb_load_yokogawa_sensor(megfile, false, false);
0067 c_weight = vb_meginfo_get_sensor_weight_meg(meg_info);
0068
0069 n_ch = vb_info_get_Nchannel(meg_info);
0070
0071 target_coil_idx = [target_idx; (n_ch + target_idx)];
0072
0073 pick_meg = pick(target_coil_idx, :);
0074 Qpick_meg = Qpick(target_coil_idx, :);
0075 c_weight_meg = c_weight(target_idx, target_coil_idx);
0076 else
0077 pick_meg = [];
0078 Qpick_meg = [];
0079 c_weight_meg = [];
0080 end
0081
0082
0083 ch_info_ref = vb_load_channel_info(megfile, 'REFERENCE');
0084 if isempty(ch_info_ref)
0085 active_swt = false;
0086 end
0087
0088 n_ref = size(ch_info_ref.Name, 1);
0089
0090 if active_swt
0091 active_idx = find(ch_info_ref.Active == true);
0092 base_names = ch_info_ref.Name(active_idx, :);
0093 else
0094 base_names = ch_info_ref.Name;
0095 end
0096
0097 base_idx = vb_util_get_matching_label_index(base_names, ch_info_cur.Name);
0098
0099 if ~isempty(base_idx)
0100 target_idx = base_idx;
0101
0102 [pick_ref, Qpick_ref] = vb_load_yokogawa_sensor(megfile, true, false);
0103 c_weight_ref = vb_meginfo_get_sensor_weight_refmg(meg_info);
0104
0105 target_coil_idx = target_idx;
0106
0107 pick_ref = pick_ref(target_coil_idx, :);
0108 Qpick_ref = Qpick_ref(target_coil_idx, :);
0109 c_weight_ref = c_weight_ref(target_idx, target_coil_idx);
0110 else
0111 pick_ref = [];
0112 Qpick_ref = [];
0113 c_weight_ref = [];
0114 end
0115
0116
0117 position = [pick_meg; pick_ref];
0118 direction = [Qpick_meg; Qpick_ref];
0119
0120 len_meg_ch = size(c_weight_meg, 1);
0121 len_meg_cl = size(c_weight_meg, 2);
0122 len_ref_ch = size(c_weight_ref, 1);
0123 len_ref_cl = size(c_weight_ref, 2);
0124
0125 len_ch = len_meg_ch + len_ref_ch;
0126 len_coil = len_meg_cl + len_ref_cl;
0127 coil_weight = zeros(len_ch, len_coil);
0128
0129
0130 coil_weight(1:len_meg_ch, 1:len_meg_cl) = c_weight_meg;
0131
0132
0133 coil_weight((len_meg_ch+1):len_ch, (len_meg_cl+1):len_coil) = c_weight_ref;
0134
0135
0136 center = [];
0137 if isfield(meg_info, 'Vcenter')
0138 center = meg_info.Vcenter;
0139 end
0140
0141 return;
0142
0143
0144
0145
0146
0147
0148
0149 function [megfile, ch_name, active_swt] = ...
0150 inner_check_arguments(megfile, ch_name, active_swt)
0151 func_ = mfilename;
0152
0153 if isempty(megfile)
0154 error('(%s) MEG-MAT file is a required parameter', func_);
0155 end
0156
0157 if exist(megfile, 'file') ~= 2
0158 error('(%s)cannot find MEG-MAT file : %s', megfile);
0159 end
0160
0161 [Measurement] = vb_load_device(megfile);
0162
0163 if ~strcmpi(Measurement, 'MEG')
0164 error('(%s)this file is not MEG file : %s', func_, megfile);
0165 end
0166
0167 if ~iscell(ch_name)
0168 ch_name = {ch_name};
0169 end
0170
0171 if isempty(ch_name{1})
0172 ch_info = vb_load_channel_info(megfile, 'MEG');
0173 ch_name = ch_info.Name;
0174 end
0175
0176 if isempty(active_swt)
0177 active_swt = false;
0178 end
0179 return;
0180
0181
0182
0183
0184
0185