0001 function job_plot_meg_load_meg(inst_id,megfile,mode,twin_lim,twin_ini)
0002
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 global vbmeg_inst;
0037 define_job_plot_meg_const;
0038
0039
0040
0041
0042
0043 if nargin<5, twin_ini = []; end
0044 if nargin<4, twin_lim = []; end
0045 if nargin<3, mode = 2; end
0046
0047
0048
0049
0050
0051 if ~exist(megfile,'file'),
0052 warndlg(['File ' megfile ' does not exist.']);
0053 return;
0054 end
0055
0056 if mode == 2,
0057 MEGinfo = vb_load_meg_info(megfile);
0058 if MEGinfo.Nrepeat>1,
0059 button = questdlg(['Which of average or raw MEG/EEG data ' ...
0060 'do you want to load?'],'Load MEG/EEG data', ...
0061 'Average','Raw','Average');
0062 if strcmp(button,'Average'),
0063 mode = 0;
0064 else
0065 mode = 1;
0066 end
0067 else
0068 mode = 0;
0069 end
0070 end
0071
0072
0073
0074
0075
0076 set(vbmeg_inst.plotmeg{inst_id}.h_fig,'Pointer','watch');
0077 drawnow;
0078
0079
0080 pick = vb_load_channel(megfile);
0081 if isempty(pick)
0082 job_plot_meg_close(inst_id);
0083 error('Specified MEG/EEG file doesn''t contain sensor position. Import data with .pos.mat file.');
0084 return;
0085 end
0086 measurement_str = vb_load_device(megfile);
0087 if strcmpi(measurement_str, 'INFO')
0088 load(megfile, 'fileinfo');
0089 measurement_str = vb_load_device(fileinfo.filename{1});
0090 end
0091 Measurement_str = upper(measurement_str);
0092 [bexp, ch_info] = vb_load_meg_data(megfile);
0093 MEGinfo = vb_load_meg_info(megfile);
0094
0095
0096 MEGinfo.ChannelInfo = ch_info;
0097
0098 if mode==0, bexp = mean(bexp,3); end
0099 pretrigger = vb_meginfo_get_pre_trigger(MEGinfo);
0100 if isempty(pretrigger), pretrigger = 0; end
0101 N = size(bexp,1);
0102 T = ((1:MEGinfo.Nsample)-pretrigger-1)*(1000/MEGinfo.SampleFreq);
0103 if isempty(twin_lim), twin_lim = [1, MEGinfo.Nsample]; end
0104 if isempty(twin_ini), twin_ini = [1, 1]; end
0105
0106 vbmeg_inst.plotmeg{inst_id}.megfile = megfile;
0107
0108 switch Measurement_str
0109 case 'MEG',
0110 vbmeg_inst.plotmeg{inst_id}.bexp = bexp*1e15;
0111 vbmeg_inst.plotmeg{inst_id}.ylabel_str = 'MEG signal [fT]';
0112 case 'EEG',
0113 vbmeg_inst.plotmeg{inst_id}.bexp = bexp*1e6;
0114 vbmeg_inst.plotmeg{inst_id}.ylabel_str = 'EEG signal [\mu V]';
0115 end
0116
0117 clear bexp;
0118 vbmeg_inst.plotmeg{inst_id}.pick = pick;
0119 vbmeg_inst.plotmeg{inst_id}.MEGinfo = MEGinfo;
0120 vbmeg_inst.plotmeg{inst_id}.N = N;
0121 vbmeg_inst.plotmeg{inst_id}.T = T;
0122 vbmeg_inst.plotmeg{inst_id}.twin_lim = twin_lim;
0123 vbmeg_inst.plotmeg{inst_id}.twin_ini = twin_ini;
0124
0125
0126 vbmeg_inst.plotmeg{inst_id}.n_trial = 1;
0127 vbmeg_inst.plotmeg{inst_id}.t = [T(min(twin_ini)) T(max(twin_ini))];
0128
0129
0130
0131
0132
0133 h = vbmeg_inst.plotmeg{inst_id}.sensor_type_menu;
0134 hh = get(h,'Children');
0135 for i=1:length(hh)
0136 delete(hh(i));
0137 end
0138
0139
0140
0141
0142
0143
0144 sensor_type_list = [];
0145 sensor_type_string = cell(0);
0146 if strcmpi(Measurement_str, 'MEG') && ~isempty(ch_info)
0147
0148
0149 meg_sensor_type_list = sort(unique(ch_info.Type));
0150
0151 for k=1:length(meg_sensor_type_list)
0152 sensor_type = meg_sensor_type_list(k);
0153 if sensor_type == 1
0154 sensor_type_list = [sensor_type_list, 1];
0155 sensor_type_string{k} = 'Magnetometer';
0156 elseif sensor_type == 2
0157 sensor_type_list = [sensor_type_list, 2];
0158 sensor_type_string{k} = 'Axial gradiometer';
0159 elseif sensor_type == 3
0160 sensor_type_list = [sensor_type_list, 3];
0161 sensor_type_string{k} = 'Planar gradiometer';
0162 end
0163 end
0164 end
0165 sensor_type_list = [sensor_type_list, -1];
0166 sensor_type_string{end+1} = 'All';
0167
0168
0169 vbmeg_inst.plotmeg{inst_id}.sensor_type_list = sensor_type_list;
0170 h = vbmeg_inst.plotmeg{inst_id}.sensor_type_menu;
0171
0172 for i=1:length(sensor_type_list)
0173 command = ['job_plot_meg_change_sensor_type(' num2str(inst_id) ...
0174 ',' num2str(i) ');'];
0175 hh = uimenu(h,'Label',sensor_type_string{i},'Callback',command, ...
0176 'Tag',['submenu' num2str(i)]);
0177 vbmeg_inst.plotmeg{inst_id}.h_sensortype(i) = hh;
0178 set(hh,'Checked','off');
0179 end
0180
0181
0182 ix = find(sensor_type_list == 2);
0183 if ~isempty(ix)
0184 vbmeg_inst.plotmeg{inst_id}.sensor_type = 2;
0185 set(vbmeg_inst.plotmeg{inst_id}.h_sensortype(ix),'Checked','on');
0186 else
0187 vbmeg_inst.plotmeg{inst_id}.sensor_type = -1;
0188 set(vbmeg_inst.plotmeg{inst_id}.h_sensortype(end),'Checked','on');
0189 end
0190
0191
0192 job_plot_meg_choose_plot_sensor(inst_id, 'reset');
0193
0194
0195
0196
0197
0198 job_plot_meg_update_spatialpattern(inst_id);
0199 job_plot_meg_update_timecourse(inst_id,FORCE_UPDATE);
0200
0201 set(vbmeg_inst.plotmeg{inst_id}.h_fig,'Pointer','arrow');
0202
0203
0204
0205
0206
0207 [tmp,fname,ext] = fileparts(megfile);
0208 set(vbmeg_inst.plotmeg{inst_id}.h_fig,'Name', ...
0209 ['job_plot_meg: ' fname ext]);