Home > vbmeg > 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 % Sensor selection method
0158 plotmeg.sensor_selection_method = 'Brush';
0159 
0160 %
0161 % GUI open
0162 %
0163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0164 h_fig = open('job_plot_meg.fig');
0165 set(h_fig,'HandleVisibility','on');
0166 
0167 % GUI components
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 % Set GUI value
0208 set(plotmeg.ed1,'String','1');
0209 plotmeg.gui_cancel = true; % when close button push, turn to false.
0210 
0211 %
0212 % Set callback functions
0213 %
0214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0215 inst_str = num2str(inst_id); 
0216 plotmeg_str = ['vbmeg_inst.plotmeg{' inst_str '}'];
0217 
0218 % Remove instance after window close
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 % Show MEG info
0226 command = ['job_plot_meg_show_meginfo(' inst_str ');'];
0227 set(plotmeg.meginfo_menu,'Callback',command);
0228 
0229 % Show loaded file
0230 command = ['job_plot_meg_show_loaded_file(' inst_str ');'];
0231 set(plotmeg.loaded_file_menu,'Callback',command);
0232 
0233 % Trial number
0234 command = ['job_plot_meg_change_trial(' inst_str ');'];
0235 set(plotmeg.ed1,'Callback',command);
0236 
0237 % Time window
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 % Time window shift
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 % Search peak
0278 command = ['global vbmeg_inst; '...
0279        'job_plot_meg_search_peak(' inst_str ');'];
0280 set(plotmeg.pb7,'Callback',command);
0281 
0282 % Plot type
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 % Print figure
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 % Save waveform
0307 command = ['job_plot_meg_save_waveform(' inst_str ');'];
0308 set(plotmeg.sw,'Callback',command);
0309 
0310 % Close window
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 % Close window(file->close)
0318 command = ['job_plot_meg_close(' inst_str ')'];
0319 set(plotmeg.close_menu,'Callback',command);
0320 
0321 % Close window(x button)
0322 command = ['job_plot_meg_close(' inst_str ', 1)'];
0323 set(plotmeg.h_fig, 'CloseRequestFcn', command);
0324 
0325 % Load MEG data
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 % Change colorscale
0334 command = ['job_plot_meg_update_spatialpattern(' inst_str ');'];
0335 set(plotmeg.ed5,'Callback',command);
0336 
0337 % Set instance
0338 vbmeg_inst.plotmeg{inst_id} = plotmeg;
0339 
0340 %
0341 % Load MEG data
0342 %
0343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0344 if ~isempty(megfile),
0345   job_plot_meg_load_meg(inst_id, megfile, mode, twin_lim, twin_ini);
0346 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005