Home > functions > job > job_plot_meg_dir > job_plot_meg.m

job_plot_meg

PURPOSE ^

Plot time course and spatial pattern of MEG data.

SYNOPSIS ^

function [twin_meg, gui_cancelled] =job_plot_meg(megfile, mode, twin_lim, twin_ini)

DESCRIPTION ^

 Plot time course and spatial pattern of MEG data. 
 Return time window which user specified on GUI.

 [syntax]
 [twin_meg,gui_cancelled] job_plot_meg(megfile,mode,twin_lim,twin_ini)

 [input]
 megfile : <<string>> MEG data file (.meg.mat)
 mode    : <optional> <<int>> 0 for loading average data
                   1 for loading all trials
                   2 for intaraction mode(default)
 twin_lim: <optional> <<int vector>> Time window selection limit(meg
           data index) e.g. twin_lim = [300, 500];
 twin_ini: <optional> <<int vector>> Initial Time window selection(meg
           data index) (default:[Pretrigger, Pretrigger] from 0msec to
           0msec) e.g. twin_ini = [300, 500];

 [output]
 twin_meg      : <<int vector>> Selected time window(meg data index)
                 e.g. twin_meg = [300, 500];
 gui_cancelled : <<bool>> gui finish state
                  = true  : close by pushing x button
                  = false : close by pushing close button 

 [note]
 If nargout==0, "OK" button dissapeared. 

 [example]
 >> job_plot_meg('./data/1002425.meg.mat');
 * return selected time window
 >> [twin_meg, gui_cancelled] = job_plot_meg('./data/1002425.meg.mat');

 [history]
 2005-03-19 Taku Yoshioka
 2006-11-17 Ryosuke Hayashi
 2007-03-27 Taku Yoshioka
 2008-09-05 Taku Yoshioka
 2011-01-19 taku-y
  [enhancement] Colorscale edit box added.

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [twin_meg, gui_cancelled] = ...
0002                           job_plot_meg(megfile, mode, twin_lim, twin_ini)
0003 % Plot time course and spatial pattern of MEG data.
0004 % Return time window which user specified on GUI.
0005 %
0006 % [syntax]
0007 % [twin_meg,gui_cancelled] job_plot_meg(megfile,mode,twin_lim,twin_ini)
0008 %
0009 % [input]
0010 % megfile : <<string>> MEG data file (.meg.mat)
0011 % mode    : <optional> <<int>> 0 for loading average data
0012 %                   1 for loading all trials
0013 %                   2 for intaraction mode(default)
0014 % twin_lim: <optional> <<int vector>> Time window selection limit(meg
0015 %           data index) e.g. twin_lim = [300, 500];
0016 % twin_ini: <optional> <<int vector>> Initial Time window selection(meg
0017 %           data index) (default:[Pretrigger, Pretrigger] from 0msec to
0018 %           0msec) e.g. twin_ini = [300, 500];
0019 %
0020 % [output]
0021 % twin_meg      : <<int vector>> Selected time window(meg data index)
0022 %                 e.g. twin_meg = [300, 500];
0023 % gui_cancelled : <<bool>> gui finish state
0024 %                  = true  : close by pushing x button
0025 %                  = false : close by pushing close button
0026 %
0027 % [note]
0028 % If nargout==0, "OK" button dissapeared.
0029 %
0030 % [example]
0031 % >> job_plot_meg('./data/1002425.meg.mat');
0032 % * return selected time window
0033 % >> [twin_meg, gui_cancelled] = job_plot_meg('./data/1002425.meg.mat');
0034 %
0035 % [history]
0036 % 2005-03-19 Taku Yoshioka
0037 % 2006-11-17 Ryosuke Hayashi
0038 % 2007-03-27 Taku Yoshioka
0039 % 2008-09-05 Taku Yoshioka
0040 % 2011-01-19 taku-y
0041 %  [enhancement] Colorscale edit box added.
0042 %
0043 % Copyright (C) 2011, ATR All Rights Reserved.
0044 % License : New BSD License(see VBMEG_LICENSE.txt)
0045 
0046 global vbmeg_inst;
0047 define_job_plot_meg_const;
0048 
0049 %
0050 % Input parameters
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 % Create GUI
0061 %
0062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0063 inst_id = create_instance;
0064 if isempty(inst_id), return; end; % Failed to create instance
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 % if return value is not specified, return.
0070 if nargout == 0, return; end
0071 %
0072 % wait for application end
0073 %
0074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0075 waitfor(h_fig);
0076 
0077 %
0078 % return value
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 %%% Inner function
0088 %%%
0089 
0090 function inst_id = create_instance
0091 % Create instance of GUI
0092 %
0093 % --- Syntax
0094 % function inst_id = create_instance
0095 %
0096 % --- History
0097 % ????-??-?? Taku Yoshioka
0098 
0099 global vbmeg_inst
0100 
0101 % instance id
0102 if isfield(vbmeg_inst,'plotmeg'),
0103   for inst_id=1:length(vbmeg_inst.plotmeg)
0104     % clean up invalid instance
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     % check container and return empty index as an inst_id
0110     if isempty(vbmeg_inst.plotmeg{inst_id}), return; end;
0111   end
0112   inst_id = length(vbmeg_inst.plotmeg)+1;
0113 else
0114   % Initialize
0115   vbmeg_inst.plotmeg = cell(0);
0116   inst_id = 1; 
0117 end
0118 
0119 %%%
0120 %%% Inner function
0121 %%%
0122 
0123 function [h_fig] = create_GUI(inst_id,megfile,mode,twin_lim,twin_ini,n)
0124 % Create GUI
0125 %
0126 % --- Syntax
0127 % function [h_fig] = create_GUI(inst_id,megfile,mode,twin_lim,twin_ini,n)
0128 %
0129 % --- History
0130 % ????-??-?? Taku Yoshioka
0131 % 2008-09-02 Taku Yoshioka
0132 
0133 global vbmeg_inst;
0134 
0135 %
0136 % Initialize parameters
0137 %
0138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0139 
0140 % MEG data
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 % Display parameters
0152 plotmeg.n_trial = [];
0153 plotmeg.t = [];
0154 plotmeg.sensor_type = [];
0155 plotmeg.sensor_type_list = [];
0156 
0157 %
0158 % GUI open
0159 %
0160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0161 h_fig = open('job_plot_meg.fig');
0162 set(h_fig,'HandleVisibility','on');
0163 
0164 % GUI components
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 % Set GUI value
0204 set(plotmeg.ed1,'String','1');
0205 plotmeg.gui_cancel = true; % when close button push, turn to false.
0206 
0207 %
0208 % Set callback functions
0209 %
0210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0211 inst_str = num2str(inst_id); 
0212 plotmeg_str = ['vbmeg_inst.plotmeg{' inst_str '}'];
0213 
0214 % Remove instance after window close
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 % Show MEG info
0222 command = ['job_plot_meg_show_meginfo(' inst_str ');'];
0223 set(plotmeg.meginfo_menu,'Callback',command);
0224 
0225 % Show loaded file
0226 command = ['job_plot_meg_show_loaded_file(' inst_str ');'];
0227 set(plotmeg.loaded_file_menu,'Callback',command);
0228 
0229 % Trial number
0230 command = ['job_plot_meg_change_trial(' inst_str ');'];
0231 set(plotmeg.ed1,'Callback',command);
0232 
0233 % Time window
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 % Time window shift
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 % Search peak
0274 command = ['global vbmeg_inst; '...
0275        'job_plot_meg_search_peak(' inst_str ');'];
0276 set(plotmeg.pb7,'Callback',command);
0277 
0278 % Plot type
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 % Print figure
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 % Close window
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 % Close window(file->close)
0310 command = ['job_plot_meg_close(' inst_str ')'];
0311 set(plotmeg.close_menu,'Callback',command);
0312 
0313 % Close window(x button)
0314 command = ['job_plot_meg_close(' inst_str ', 1)'];
0315 set(plotmeg.h_fig, 'CloseRequestFcn', command);
0316 
0317 % Load MEG data
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 % Change colorscale
0326 command = ['job_plot_meg_update_spatialpattern(' inst_str ');'];
0327 set(plotmeg.ed5,'Callback',command);
0328 
0329 % Set instance
0330 vbmeg_inst.plotmeg{inst_id} = plotmeg;
0331 
0332 %
0333 % Load MEG data
0334 %
0335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0336 if ~isempty(megfile),
0337   job_plot_meg_load_meg(inst_id, megfile, mode, twin_lim, twin_ini);
0338 end

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005