0001 function [twin_meg, gui_cancelled] = ...
0002 job_plot_meg(megfile, mode, twin_lim, twin_ini)
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
0045
0046 global vbmeg_inst;
0047 define_job_plot_meg_const;
0048
0049
0050
0051
0052
0053 if ~exist('mode', 'var'), mode = 2; end;
0054 if isempty(mode), mode = 2; end;
0055 if ~exist('twin_ini', 'var'), twin_ini = [1 1]; end;
0056 if ~exist('megfile', 'var'), megfile = []; end
0057 if ~exist('twin_lim', 'var'), twin_lim = []; end
0058
0059
0060
0061
0062
0063 inst_id = create_instance;
0064 if isempty(inst_id), return; end;
0065 h_fig = create_GUI(inst_id, megfile,mode, twin_lim, twin_ini,nargout);
0066 job_plot_meg_update_timecourse(inst_id, FORCE_UPDATE);
0067 job_plot_meg_update_spatialpattern(inst_id);
0068
0069
0070 if nargout == 0, return; end
0071
0072
0073
0074
0075 waitfor(h_fig);
0076
0077
0078
0079
0080
0081 twin_meg = vbmeg_inst.plotmeg{inst_id}.twin_meg;
0082 gui_cancelled = vbmeg_inst.plotmeg{inst_id}.gui_cancel;
0083 vbmeg_inst.plotmeg{inst_id} = [];
0084
0085
0086
0087
0088
0089
0090 function inst_id = create_instance
0091
0092
0093
0094
0095
0096
0097
0098
0099 global vbmeg_inst
0100
0101
0102 if isfield(vbmeg_inst,'plotmeg'),
0103 for inst_id=1:length(vbmeg_inst.plotmeg)
0104
0105 if isfield(vbmeg_inst.plotmeg{inst_id}, 'h_fig') && ...
0106 ~ishandle(vbmeg_inst.plotmeg{inst_id}.h_fig)
0107 vbmeg_inst.plotmeg{inst_id} = [];
0108 end
0109
0110 if isempty(vbmeg_inst.plotmeg{inst_id}), return; end;
0111 end
0112 inst_id = length(vbmeg_inst.plotmeg)+1;
0113 else
0114
0115 vbmeg_inst.plotmeg = cell(0);
0116 inst_id = 1;
0117 end
0118
0119
0120
0121
0122
0123 function [h_fig] = create_GUI(inst_id,megfile,mode,twin_lim,twin_ini,n)
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133 global vbmeg_inst;
0134
0135
0136
0137
0138
0139
0140
0141 plotmeg.megfile = [];
0142 plotmeg.bexp = [];
0143 plotmeg.pick = [];
0144 plotmeg.MEGinfo = [];
0145 plotmeg.T = [];
0146 plotmeg.N = [];
0147 plotmeg.twin_lim = [];
0148 plotmeg.twin_meg = [];
0149 plotmeg.cancel = [];
0150
0151
0152 plotmeg.n_trial = [];
0153 plotmeg.t = [];
0154 plotmeg.sensor_type = [];
0155 plotmeg.sensor_type_list = [];
0156
0157
0158 plotmeg.sensor_selection_method = 'Brush';
0159
0160
0161
0162
0163
0164 h_fig = open('job_plot_meg.fig');
0165 set(h_fig,'HandleVisibility','on');
0166
0167
0168 plotmeg.h_fig = h_fig;
0169 plotmeg.h_time = get_child_handle(h_fig,'plot_time');
0170 plotmeg.h_space = get_child_handle(h_fig,'plot_space');
0171 plotmeg.ed1 = get_child_handle(h_fig,'trial_number');
0172 plotmeg.ed2 = get_child_handle(h_fig,'time_window_start');
0173 plotmeg.ed3 = get_child_handle(h_fig,'time_window_end');
0174 plotmeg.ed4 = get_child_handle(h_fig,'temporal_peak_size');
0175 plotmeg.ed5 = get_child_handle(h_fig,'edit7');
0176 plotmeg.pb1 = get_child_handle(h_fig,'print_space');
0177 plotmeg.pb2 = get_child_handle(h_fig,'print_time');
0178 plotmeg.sw = get_child_handle(h_fig, 'save_waveform_push');
0179 plotmeg.pb3 = get_child_handle(h_fig,'move_forward');
0180 plotmeg.pb4 = get_child_handle(h_fig,'move_forward_fast');
0181 plotmeg.pb5 = get_child_handle(h_fig,'move_back');
0182 plotmeg.pb6 = get_child_handle(h_fig,'move_back_fast');
0183 plotmeg.pb7 = get_child_handle(h_fig,'temporal_peak');
0184 plotmeg.cb1 = get_child_handle(h_fig,'fix_colormap');
0185 plotmeg.rb1 = get_child_handle(h_fig,'power_plot');
0186 plotmeg.rb2 = get_child_handle(h_fig,'sensor_plot');
0187 plotmeg.twin_min_range = get_child_handle(h_fig, 'time_window_min');
0188 plotmeg.twin_max_range = get_child_handle(h_fig, 'time_window_max');
0189 plotmeg.close_push = get_child_handle(h_fig, 'close_push');
0190 plotmeg.load_meg_menu ...
0191 = get_child_handle(get_child_handle(h_fig,'file_menu'), ...
0192 'load_meg_menu');
0193 plotmeg.loaded_file_menu ...
0194 = get_child_handle(get_child_handle(h_fig,'file_menu'), ...
0195 'loaded_file_menu');
0196 plotmeg.meginfo_menu ...
0197 = get_child_handle(get_child_handle(h_fig,'file_menu'), ...
0198 'meginfo_menu');
0199 plotmeg.close_menu ...
0200 = get_child_handle(get_child_handle(h_fig,'file_menu'), ...
0201 'close_menu');
0202 plotmeg.sensor_type_menu ...
0203 = get_child_handle(get_child_handle(h_fig,'view_menu'), ...
0204 'sensor_type_menu');
0205
0206
0207
0208 set(plotmeg.ed1,'String','1');
0209 plotmeg.gui_cancel = true;
0210
0211
0212
0213
0214
0215 inst_str = num2str(inst_id);
0216 plotmeg_str = ['vbmeg_inst.plotmeg{' inst_str '}'];
0217
0218
0219 if n == 0
0220 command = ['global vbmeg_inst; '...
0221 'vbmeg_inst.plotmeg{' inst_str '}=[];'];
0222 set(h_fig,'DeleteFcn',command);
0223 end
0224
0225
0226 command = ['job_plot_meg_show_meginfo(' inst_str ');'];
0227 set(plotmeg.meginfo_menu,'Callback',command);
0228
0229
0230 command = ['job_plot_meg_show_loaded_file(' inst_str ');'];
0231 set(plotmeg.loaded_file_menu,'Callback',command);
0232
0233
0234 command = ['job_plot_meg_change_trial(' inst_str ');'];
0235 set(plotmeg.ed1,'Callback',command);
0236
0237
0238 command = ['global vbmeg_inst; ' ...
0239 plotmeg_str '.t(1)=' ...
0240 'str2num(get(' plotmeg_str '.ed2,''String''));' ...
0241 'job_plot_meg_update_timecourse(' inst_str ');' ...
0242 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0243 set(plotmeg.ed2,'Callback',command);
0244 command = ['global vbmeg_inst; ' ...
0245 plotmeg_str '.t(2)=' ...
0246 'str2num(get(' plotmeg_str '.ed3,''String''));' ...
0247 'job_plot_meg_update_timecourse(' inst_str ');' ...
0248 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0249 set(plotmeg.ed3,'Callback',command);
0250
0251
0252 command = ['global vbmeg_inst; '...
0253 'dt = ' plotmeg_str '.t(2)-' plotmeg_str '.t(1);' ...
0254 plotmeg_str '.t=' plotmeg_str '.t+dt;' ...
0255 'job_plot_meg_update_timecourse(' inst_str ');' ...
0256 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0257 set(plotmeg.pb3,'Callback',command);
0258 command = ['global vbmeg_inst; '...
0259 'dt = ' plotmeg_str '.t(2)-' plotmeg_str '.t(1);' ...
0260 plotmeg_str '.t=' plotmeg_str '.t+5*dt;' ...
0261 'job_plot_meg_update_timecourse(' inst_str ');' ...
0262 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0263 set(plotmeg.pb4,'Callback',command);
0264 command = ['global vbmeg_inst; '...
0265 'dt = ' plotmeg_str '.t(2)-' plotmeg_str '.t(1);' ...
0266 plotmeg_str '.t=' plotmeg_str '.t-dt;' ...
0267 'job_plot_meg_update_timecourse(' inst_str ');' ...
0268 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0269 set(plotmeg.pb5,'Callback',command);
0270 command = ['global vbmeg_inst; '...
0271 'dt = ' plotmeg_str '.t(2)-' plotmeg_str '.t(1);' ...
0272 plotmeg_str '.t=' plotmeg_str '.t-5*dt;' ...
0273 'job_plot_meg_update_timecourse(' inst_str ');' ...
0274 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0275 set(plotmeg.pb6,'Callback',command);
0276
0277
0278 command = ['global vbmeg_inst; '...
0279 'job_plot_meg_search_peak(' inst_str ');'];
0280 set(plotmeg.pb7,'Callback',command);
0281
0282
0283 command = ['global vbmeg_inst;'...
0284 'define_job_plot_meg_const;'...
0285 'set(' plotmeg_str '.rb2,''Value'',0);' ...
0286 'job_plot_meg_update_timecourse(' ...
0287 inst_str ',FORCE_UPDATE);'];
0288 set(plotmeg.rb1,'Callback',command);
0289
0290 command = ['global vbmeg_inst;' ...
0291 'define_job_plot_meg_const;' ...
0292 'set(' plotmeg_str '.rb1,''Value'',0);' ...
0293 'job_plot_meg_update_timecourse(' ...
0294 inst_str ',FORCE_UPDATE);'];
0295 set(plotmeg.rb2,'Callback',command);
0296
0297 command = ['job_plot_meg_update_spatialpattern(' inst_str ');'];
0298 set(plotmeg.cb1,'Callback',command);
0299
0300
0301 command = ['job_plot_meg_print_spatialpattern(' inst_str ');'];
0302 set(plotmeg.pb1,'Callback',command);
0303 command = ['job_plot_meg_print_timecourse(' inst_str ');'];
0304 set(plotmeg.pb2,'Callback',command);
0305
0306
0307 command = ['job_plot_meg_save_waveform(' inst_str ');'];
0308 set(plotmeg.sw,'Callback',command);
0309
0310
0311 command = ['global vbmeg_inst; '...
0312 'vbmeg_inst.plotmeg{' inst_str '}.gui_cancel = false;',...
0313 'closereq;'];
0314 set(plotmeg.close_push, 'Callback', command);
0315 if n==0, set(plotmeg.close_push,'Visible','off'); end
0316
0317
0318 command = ['job_plot_meg_close(' inst_str ')'];
0319 set(plotmeg.close_menu,'Callback',command);
0320
0321
0322 command = ['job_plot_meg_close(' inst_str ', 1)'];
0323 set(plotmeg.h_fig, 'CloseRequestFcn', command);
0324
0325
0326 command = ['[meg_dir,meg_file] = vb_file_select' ...
0327 '({''.meg.mat'',''.eeg.mat''},''Load MEG/EEG data'');' ...
0328 'if ~isempty(meg_file), ' ...
0329 'job_plot_meg_load_meg(' inst_str ',' ...
0330 '[meg_dir filesep meg_file{1}]); end'];
0331 set(plotmeg.load_meg_menu,'Callback',command);
0332
0333
0334 command = ['job_plot_meg_update_spatialpattern(' inst_str ');'];
0335 set(plotmeg.ed5,'Callback',command);
0336
0337
0338 vbmeg_inst.plotmeg{inst_id} = plotmeg;
0339
0340
0341
0342
0343
0344 if ~isempty(megfile),
0345 job_plot_meg_load_meg(inst_id, megfile, mode, twin_lim, twin_ini);
0346 end