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
0159
0160
0161 h_fig = open('job_plot_meg.fig');
0162 set(h_fig,'HandleVisibility','on');
0163
0164
0165 plotmeg.h_fig = h_fig;
0166 plotmeg.h_time = get_child_handle(h_fig,'plot_time');
0167 plotmeg.h_space = get_child_handle(h_fig,'plot_space');
0168 plotmeg.ed1 = get_child_handle(h_fig,'trial_number');
0169 plotmeg.ed2 = get_child_handle(h_fig,'time_window_start');
0170 plotmeg.ed3 = get_child_handle(h_fig,'time_window_end');
0171 plotmeg.ed4 = get_child_handle(h_fig,'temporal_peak_size');
0172 plotmeg.ed5 = get_child_handle(h_fig,'edit7');
0173 plotmeg.pb1 = get_child_handle(h_fig,'print_space');
0174 plotmeg.pb2 = get_child_handle(h_fig,'print_time');
0175 plotmeg.pb3 = get_child_handle(h_fig,'move_forward');
0176 plotmeg.pb4 = get_child_handle(h_fig,'move_forward_fast');
0177 plotmeg.pb5 = get_child_handle(h_fig,'move_back');
0178 plotmeg.pb6 = get_child_handle(h_fig,'move_back_fast');
0179 plotmeg.pb7 = get_child_handle(h_fig,'temporal_peak');
0180 plotmeg.cb1 = get_child_handle(h_fig,'fix_colormap');
0181 plotmeg.rb1 = get_child_handle(h_fig,'power_plot');
0182 plotmeg.rb2 = get_child_handle(h_fig,'sensor_plot');
0183 plotmeg.twin_min_range = get_child_handle(h_fig, 'time_window_min');
0184 plotmeg.twin_max_range = get_child_handle(h_fig, 'time_window_max');
0185 plotmeg.close_push = get_child_handle(h_fig, 'close_push');
0186 plotmeg.load_meg_menu ...
0187 = get_child_handle(get_child_handle(h_fig,'file_menu'), ...
0188 'load_meg_menu');
0189 plotmeg.loaded_file_menu ...
0190 = get_child_handle(get_child_handle(h_fig,'file_menu'), ...
0191 'loaded_file_menu');
0192 plotmeg.meginfo_menu ...
0193 = get_child_handle(get_child_handle(h_fig,'file_menu'), ...
0194 'meginfo_menu');
0195 plotmeg.close_menu ...
0196 = get_child_handle(get_child_handle(h_fig,'file_menu'), ...
0197 'close_menu');
0198 plotmeg.sensor_type_menu ...
0199 = get_child_handle(get_child_handle(h_fig,'view_menu'), ...
0200 'sensor_type_menu');
0201
0202
0203
0204 set(plotmeg.ed1,'String','1');
0205 plotmeg.gui_cancel = true;
0206
0207
0208
0209
0210
0211 inst_str = num2str(inst_id);
0212 plotmeg_str = ['vbmeg_inst.plotmeg{' inst_str '}'];
0213
0214
0215 if n == 0
0216 command = ['global vbmeg_inst; '...
0217 'vbmeg_inst.plotmeg{' inst_str '}=[];'];
0218 set(h_fig,'DeleteFcn',command);
0219 end
0220
0221
0222 command = ['job_plot_meg_show_meginfo(' inst_str ');'];
0223 set(plotmeg.meginfo_menu,'Callback',command);
0224
0225
0226 command = ['job_plot_meg_show_loaded_file(' inst_str ');'];
0227 set(plotmeg.loaded_file_menu,'Callback',command);
0228
0229
0230 command = ['job_plot_meg_change_trial(' inst_str ');'];
0231 set(plotmeg.ed1,'Callback',command);
0232
0233
0234 command = ['global vbmeg_inst; ' ...
0235 plotmeg_str '.t(1)=' ...
0236 'str2num(get(' plotmeg_str '.ed2,''String''));' ...
0237 'job_plot_meg_update_timecourse(' inst_str ');' ...
0238 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0239 set(plotmeg.ed2,'Callback',command);
0240 command = ['global vbmeg_inst; ' ...
0241 plotmeg_str '.t(2)=' ...
0242 'str2num(get(' plotmeg_str '.ed3,''String''));' ...
0243 'job_plot_meg_update_timecourse(' inst_str ');' ...
0244 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0245 set(plotmeg.ed3,'Callback',command);
0246
0247
0248 command = ['global vbmeg_inst; '...
0249 'dt = ' plotmeg_str '.t(2)-' plotmeg_str '.t(1);' ...
0250 plotmeg_str '.t=' plotmeg_str '.t+dt;' ...
0251 'job_plot_meg_update_timecourse(' inst_str ');' ...
0252 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0253 set(plotmeg.pb3,'Callback',command);
0254 command = ['global vbmeg_inst; '...
0255 'dt = ' plotmeg_str '.t(2)-' plotmeg_str '.t(1);' ...
0256 plotmeg_str '.t=' plotmeg_str '.t+5*dt;' ...
0257 'job_plot_meg_update_timecourse(' inst_str ');' ...
0258 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0259 set(plotmeg.pb4,'Callback',command);
0260 command = ['global vbmeg_inst; '...
0261 'dt = ' plotmeg_str '.t(2)-' plotmeg_str '.t(1);' ...
0262 plotmeg_str '.t=' plotmeg_str '.t-dt;' ...
0263 'job_plot_meg_update_timecourse(' inst_str ');' ...
0264 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0265 set(plotmeg.pb5,'Callback',command);
0266 command = ['global vbmeg_inst; '...
0267 'dt = ' plotmeg_str '.t(2)-' plotmeg_str '.t(1);' ...
0268 plotmeg_str '.t=' plotmeg_str '.t-5*dt;' ...
0269 'job_plot_meg_update_timecourse(' inst_str ');' ...
0270 'job_plot_meg_update_spatialpattern(' inst_str ');'];
0271 set(plotmeg.pb6,'Callback',command);
0272
0273
0274 command = ['global vbmeg_inst; '...
0275 'job_plot_meg_search_peak(' inst_str ');'];
0276 set(plotmeg.pb7,'Callback',command);
0277
0278
0279 command = ['global vbmeg_inst;'...
0280 'define_job_plot_meg_const;'...
0281 'set(' plotmeg_str '.rb2,''Value'',0);' ...
0282 'job_plot_meg_update_timecourse(' ...
0283 inst_str ',FORCE_UPDATE);'];
0284 set(plotmeg.rb1,'Callback',command);
0285
0286 command = ['global vbmeg_inst;' ...
0287 'define_job_plot_meg_const;' ...
0288 'set(' plotmeg_str '.rb1,''Value'',0);' ...
0289 'job_plot_meg_update_timecourse(' ...
0290 inst_str ',FORCE_UPDATE);'];
0291 set(plotmeg.rb2,'Callback',command);
0292
0293 command = ['job_plot_meg_update_spatialpattern(' inst_str ');'];
0294 set(plotmeg.cb1,'Callback',command);
0295
0296
0297 command = ['job_plot_meg_print_spatialpattern(' inst_str ');'];
0298 set(plotmeg.pb1,'Callback',command);
0299 command = ['job_plot_meg_print_timecourse(' inst_str ');'];
0300 set(plotmeg.pb2,'Callback',command);
0301
0302
0303 command = ['global vbmeg_inst; '...
0304 'vbmeg_inst.plotmeg{' inst_str '}.gui_cancel = false;',...
0305 'closereq;'];
0306 set(plotmeg.close_push, 'Callback', command);
0307 if n==0, set(plotmeg.close_push,'Visible','off'); end
0308
0309
0310 command = ['job_plot_meg_close(' inst_str ')'];
0311 set(plotmeg.close_menu,'Callback',command);
0312
0313
0314 command = ['job_plot_meg_close(' inst_str ', 1)'];
0315 set(plotmeg.h_fig, 'CloseRequestFcn', command);
0316
0317
0318 command = ['[meg_dir,meg_file] = vb_file_select' ...
0319 '({''.meg.mat'',''.eeg.mat''},''Load MEG/EEG data'');' ...
0320 'if ~isempty(meg_file), ' ...
0321 'job_plot_meg_load_meg(' inst_str ',' ...
0322 '[meg_dir filesep meg_file{1}]); end'];
0323 set(plotmeg.load_meg_menu,'Callback',command);
0324
0325
0326 command = ['job_plot_meg_update_spatialpattern(' inst_str ');'];
0327 set(plotmeg.ed5,'Callback',command);
0328
0329
0330 vbmeg_inst.plotmeg{inst_id} = plotmeg;
0331
0332
0333
0334
0335
0336 if ~isempty(megfile),
0337 job_plot_meg_load_meg(inst_id, megfile, mode, twin_lim, twin_ini);
0338 end