0001 function vb_megfile_make_loaded_megfile(megfile, ...
0002 ch_list, loaddata, newfile, overswt, coord_type)
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_list', 'var'), ch_list = []; end
0039 if ~exist('loaddata', 'var'), loaddata = []; end
0040 if ~exist('newfile', 'var'), newfile = []; end
0041 if ~exist('overswt', 'var'), overswt = []; end
0042 if ~exist('coord_type', 'var'), coord_type = ''; end
0043 [megfile, ch_list, loaddata, newfile, overswt, coord_type] = ...
0044 inner_check_arguments(megfile, ...
0045 ch_list, loaddata, newfile, overswt, coord_type);
0046
0047
0048
0049 func_ = mfilename;
0050 error('(%s) !!!SORRY THIS FUNCTION PROHIBITED!!!', func_);
0051
0052 bexp = [];
0053 eeg = [];
0054 refmg = [];
0055
0056 MEGinfo = [];
0057
0058 ExtraChannelInfo = [];
0059 saveman = [];
0060
0061 Nchannel_all = size(loaddata,1);
0062 Nsample = size(loaddata,2);
0063 Ntrial = size(loaddata,3);
0064
0065 [meginfo] = vb_megfile_load_meginfo(megfile);
0066 [swm] = vb_meginfo_get_sensor_weight_meg(meginfo);
0067 [swr] = vb_meginfo_get_sensor_weight_refmg(meginfo);
0068 [p,qp] = vb_load_sensor(megfile, 'MEG');
0069 [ref_p,ref_qp] = vb_load_sensor(megfile, 'REF');
0070
0071 [ch_info] = vb_megfile_get_applicable_channel(megfile, ch_list);
0072
0073
0074 meg_ch = vb_ch_info_get_channel_list_meg(ch_info);
0075 if ~isempty(meg_ch)
0076
0077 org_meg_ch = vb_meginfo_get_channel_label_meg(meginfo);
0078
0079 [res, idx] = vb_util_is_included_list(org_meg_ch, meg_ch);
0080 pick = p(idx,:);
0081 Qpick = qp(idx,:);
0082 if ~isempty(swm)
0083 sensor_weight = swm(idx,:);
0084 end
0085 Nchannel_meg = length(meg_ch,1);
0086
0087 MEGch_id = idx;
0088 bexp = loaddata(1:Nchannel_meg,:,:);
0089
0090 else
0091 Nchannel_meg = 0;
0092 MEGch_id = [];
0093 MEGch_name = [];
0094 pick = [];
0095 Qpick = [];
0096 sensor_weight = [];
0097 end
0098
0099
0100 ext_ch = vb_ch_info_get_channel_list_ext(ch_info);
0101 if ~isempty(ext_ch)
0102 Nchannel_ext = size(ext_ch,1);
0103 ch_start = Nchannel_meg;
0104 EXTch_id = (ch_start+1):(ch_start+Nchannel_ext);
0105 eeg = loaddata(EXTch_id,:,:);
0106
0107 else
0108 Nchannel_ext = 0;
0109 EXTch_id = [];
0110 end
0111
0112
0113
0114 ref_ch = vb_ch_info_get_channel_list_ref(ch_info);
0115 if ~isempty(ref_ch)
0116 Nchannel_ref = size(ref_ch,1);
0117 ch_start = Nchannel_meg+Nchannel_ext;
0118 REFch_id = (ch_start+1):(ch_start+Nchannel_ref);
0119 refmg = loaddata(REFch_id,:,:);
0120
0121
0122 org_ref_ch = vb_meginfo_get_channel_label_refmg(meginfo);
0123 [res, idx] = vb_util_check_numerical_lists(org_ref_ch, ref_ch);
0124 ref_pick = ref_p(idx,:);
0125 ref_Qpick = ref_qp(idx,:);
0126
0127 if ~isempty(swr)
0128 sensor_weight_ref = swr(idx,:);
0129 end
0130
0131 else
0132 Nchannel_ref = 0;
0133 REFch_id = [];
0134 ref_pick = [];
0135 ref_Qpick = [];
0136 sensor_weight_ref = [];
0137 end
0138
0139
0140 MEGinfo = vb_megfile_load_meginfo(megfile);
0141 MEGinfo.Nchannel_all = Nchannel_all;
0142 MEGinfo.Nchannel_org = Nchannel_meg;
0143 MEGinfo.Nchannel = Nchannel_meg;
0144
0145 MEGinfo.sensor_weight = sensor_weight;
0146
0147 MEGinfo = vb_meginfo_set_sensor_weight_refmg(MEGinfo, sensor_weight_ref);
0148
0149 MEGinfo.Nsample = Nsample;
0150 MEGinfo.Nrepeat_org = Ntrial;
0151 MEGinfo.Nrepeat = Ntrial;
0152 MEGinfo.TrialNumber = Ntrial;
0153 MEGinfo.MEGch_id = MEGch_id;
0154 MEGinfo.MEGch_name = meg_ch;
0155 MEGinfo.ExtraChannelInfo = ExtraChannelInfo;
0156 MEGinfo.saveman = saveman;
0157
0158 [Measurement] = vb_megfile_get_measurement(megfile);
0159
0160
0161
0162
0163
0164
0165
0166 MEGinfo.EEGinfo = vb_meginfo_filter_EEGinfo(meginfo, ch_list);
0167
0168
0169
0170 if (exist(newfile, 'file') == 2 && overswt) ...
0171 || exist(newfile, 'file') ~= 2
0172
0173 vb_fsave(newfile, 'MEGinfo', 'pick', 'Qpick', 'ref_pick', 'ref_Qpick', ...
0174 'Measurement', 'bexp', 'eeg', 'refmg');
0175 else
0176 warning('(%s)cannot overwrite new MEG-MAT file : %s\n', func_, newfile);
0177 end
0178
0179
0180
0181
0182
0183
0184
0185 function [megfile, ch_list, loaddata, newfile, overswt, coord_type] = ...
0186 inner_check_arguments(megfile, ...
0187 ch_list, loaddata, newfile, overswt, coord_type)
0188 func_ = mfilename;
0189 if isempty(megfile)
0190 error('(%s)megfile is a required parameter', func_);
0191 end
0192
0193 if isempty(ch_list)
0194 error('(%s)ch_list is a required parameter', func_);
0195 end
0196
0197 if isempty(loaddata)
0198 error('(%s)loaddata is a required parameter', func_);
0199 end
0200
0201 if isempty(newfile)
0202 error('(%s)newfile is a required parameter', func_);
0203 end
0204
0205 if isempty(overswt)
0206 overswt = true;
0207 end
0208
0209 if isempty(coord_type)
0210
0211 end
0212
0213
0214 if exist(megfile, 'file') ~= 2
0215 error('(%s)cannot find megfile : %s', megfile);
0216 end
0217
0218
0219 if size(vb_util_arrange_list(ch_list,1),2) ~= size(loaddata,1)
0220 error('(%s)channel sizes are different ch_list and loaddata', func_);
0221 end
0222 return;
0223
0224
0225
0226