⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 erp_plot_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 5 页
字号:
%ERP_PLOT_UI Plot ERP waveforms
%
%  USAGE: erp_plot_ui({datamat_file,view_option})
%
%   ERP_PLOT_UI({datamat_file}) will plot grand mean of datamat_file.
%

%   Called by ERP_CREATE_DATAMAT, ERP_MODIFY_DATAMAT, ERP_RESULT_UI
%		ERP_SHOWPLOT_UI, ERP_PLOT_UI
%
%   I (datamat_file) - Matlab data file that contains a structure array
%			with the datamat information for the study
%			or the result file
%
%   I (view_option) -	1: subject amplitude
%			2: average amplitude 
%			3: salience
%			4: group subj
%			5: behavior corr
%
%   Created on 25-NOV-2002 by Jimmy Shen
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function fig = erp_plot_ui(varargin)

   if nargin == 0 | ~ischar(varargin{1})	% input is not action

      datamat_file = varargin{1}{1};
      view_option = varargin{1}{2};
      if size(varargin{1},2) == 3
         fig = varargin{1}{3};
      else
         fig = [];
      end

      msg = 'Loading ERP data ...  Please wait !';
      h = rri_wait_box(msg,[0.6 0.1]);

      fig = init(datamat_file, view_option, fig);

      delete(h);

      return;

   end

   action = varargin{1};

   if strcmp(action,'zoom')			% zoom menu clicked
      zoom_on_state = get(gcbo,'Userdata');
      if (zoom_on_state == 1)			% zoom on
         zoom on;
         set(gcbo,'Userdata',0,'Label','&Zoom off');
         set(gcf,'pointer','crosshair');
      else					% zoom off
         zoom off;
         set(gcf,'buttondown','erp_plot_ui(''fig_bt_dn'');');
         set(gcbo,'Userdata',1,'Label','&Zoom on');
         set(gcf,'pointer','arrow');
      end
   elseif strcmp(action,'legend')		% legend menu clicked
      legend_on_state = get(gcbo,'Userdata');
      if (legend_on_state == 1)			% legend on
         old_pointer = get(gcf,'pointer');
         set(gcf,'pointer','watch');
         display_legend('on');
         set(gcbo,'Userdata',0,'Label','&Legend off');
         set(gcf,'pointer',old_pointer);
      else					% legend off
         display_legend('off');
         set(gcbo,'Userdata',1,'Label','&Legend on');
      end
   elseif strcmp(action,'choose_font_size')
      choose_font_size;
   elseif strcmp(action,'move_slider')
      move_slider;
   elseif strcmp(action, 'toggle_avg')
      toggle_avg;
   elseif strcmp(action, 'toggle_salience')
      datamat_file = getappdata(gcf,'datamat_file');
      close(gcf);
      erp_plot_ui({datamat_file,3});
   elseif strcmp(action, 'toggle_subj')
      toggle_subj;
   elseif strcmp(action, 'toggle_corr')
      toggle_corr;
   elseif strcmp(action, 'toggle_detail')
      toggle_detail;
   elseif strcmp(action, 'toggle_eigen')
      toggle_eigen;
   elseif strcmp(action, 'toggle_score')
      toggle_score;
   elseif strcmp(action, 'toggle_brain')
      toggle_brain;
   elseif strcmp(action, 'toggle_canonical')
      toggle_canonical;
   elseif strcmp(action, 'toggle_canonicalcorr')
      toggle_canonicalcorr;
   elseif strcmp(action, 'toggle_contrast')
      toggle_contrast;
   elseif strcmp(action,'toggle_chan_name')
      toggle_chan_name;
   elseif strcmp(action,'toggle_chan_axes')
      toggle_chan_axes;
   elseif strcmp(action,'toggle_chan_tick')
      toggle_chan_tick;
   elseif strcmp(action,'display_chan_name')
      display_chan_name(varargin{2});
   elseif strcmp(action,'display_chan_axes')
      display_chan_axes(varargin{2});
   elseif strcmp(action,'display_chan_tick')
      display_chan_tick(varargin{2});
   elseif strcmp(action,'option_menu')
      option_menu;
   elseif strcmp(action,'bs_option_menu')
      bs_option_menu;
   elseif strcmp(action,'cond_mean')
      cond_mean;
   elseif strcmp(action,'cond_diff')
      cond_diff;
   elseif strcmp(action,'select_wave')
      select_wave;
   elseif strcmp(action,'select_chan_name')
      select_chan_name;
   elseif strcmp(action,'select_rubber_chan')
      select_rubber_chan;
   elseif strcmp(action,'select_all_chan')
      select_all_chan;
   elseif strcmp(action,'reset_all_chan')
      reset_all_chan;
   elseif strcmp(action,'modify_datamat')
      modify_datamat;
   elseif strcmp(action,'fig_bt_dn')
      fig_bt_dn
   elseif strcmp(action,'delete_fig')
      delete_fig;
   end

   return;					% erp_plot_ui


%
%  initialize GUI
%
%-------------------------------------------------------------

function h0 = init(datamat_file, view_option, fig)

   % initial setting value
   %
   avg_amplitude = [];		% grand average of subjects along condition
   bs_amplitude = [];		% bootstrap wave matrix
   wave_selection = [];		% wave chosen to display from option menu
   avg_selection = [];		% grand average chosen to display
   bs_selection = [];		% bootstrap LVs chosen to display
   bs_ratio = [];		% bootstrap ratio data
   bs_field = [];		% bootstrap field contains bootstrap setting
				% value for all LVs
   mean_wave_list = {};		% new condition which is obtained by averaging others
   mean_wave_name = {};		% name for mean_wave_list
   cond_couple_lst = [];	% condition couple list chosn by user to do cond_diff
   org_wave_name = [];		% original condition name before cond_diff
   org_wave_amplitude = [];	% original wave amplitude before cond_diff
   org_selected_wave = [];	% original selected wave before cond_diff
   x_interval_selection = [];	% x tick value
   y_interval_selection = [];	% y tick value
   font_size_selection =[];	% font size
   eta = [];			% wave size
   chan_name_status = [];	% display channel name?
   chan_axes_status = [];	% display channel axes?
   chan_tick_status = [];	% display channel tick?
   rescale = [];
   s = [];
   old_setting = [];		% saved setting information

   setting1 = [];
   setting2 = [];
   setting3 = [];
   setting4 = [];
   setting5 = [];

   switch view_option		% what to plot?
      case {1}                          %  subj
         try
            load(datamat_file, 'setting1');
            setting = setting1;
         catch
            setting = [];
         end
         fig_name = ['ERP Amplitude: ' datamat_file];
	 fig_user = '';
      case {2}                          %  avg
         try
            load(datamat_file, 'setting2');
            setting = setting2;
         catch
            setting = [];
         end
         fig_name = ['Grand Average Amplitude: ' datamat_file];
	 fig_user = 'Grand Average of ERP Amplitude';
      case {3}                          %  salience
         try
            load(datamat_file, 'setting3');
            setting = setting3;
         catch
            setting = [];
         end
         fig_name = ['Electrodes Salience: ' datamat_file];
	 fig_user = '';
      case {4}                          %  grp
         try
            load(datamat_file, 'setting4');
            setting = setting4;
         catch
            setting = [];
         end
         fig_name = ['Group Subject Amplitude: ' datamat_file];
	 fig_user = 'Group Subject of ERP Amplitude';
      case {5}                          %  corr
         try
            load(datamat_file, 'setting5');
            setting = setting5;
         catch
            setting = [];
         end
         fig_name = ['Spatiotemporal Correlations: ' datamat_file];
	 fig_user = 'Spatiotemporal Correlations';
      otherwise                         %  error
         msg = 'ERROR: No this view option.';
         msgbox(msg,'ERROR','modal');
         return;
   end

   %  load setting value, should be:
   %  either got all value, or none value
   %
   if ~isempty(setting)		% there is setting saved; not new file
      wave_selection = setting.wave_selection;
      avg_selection = setting.avg_selection;
      bs_selection = setting.bs_selection;
      bs_field = setting.bs_field;

      %  new field added later, need verify
      %
      if isfield(setting,'mean_wave_list')
         mean_wave_list = setting.mean_wave_list;
      end

      if isfield(setting,'mean_wave_name')
         mean_wave_name = setting.mean_wave_name;
      end

      if isfield(setting,'cond_couple_lst')
         cond_couple_lst = setting.cond_couple_lst;
      end

      x_interval_selection = setting.x_interval_selection;
      y_interval_selection = setting.y_interval_selection;

      if isfield(setting,'rescale')
         rescale = setting.rescale;
      end

      font_size_selection = setting.font_size_selection;
      eta = setting.eta;
      chan_name_status = setting.chan_name_status;
      chan_axes_status = setting.chan_axes_status;
      chan_tick_status = setting.chan_tick_status;

      old_setting = setting;
   end

   if isempty(rescale)
      rescale = 1;
      setting.rescale = rescale;
   end

   if isempty(font_size_selection)
      font_size_selection = 4;
      setting.font_size_selection = font_size_selection;
   end

   if isempty(eta)
      eta = 0.07;
      setting.eta = eta;
   end

   if isempty(chan_name_status)
      chan_name_status = 1;
      setting.chan_name_status = chan_name_status;
   end

   if isempty(chan_axes_status)
      chan_axes_status = 1;
      setting.chan_axes_status = chan_axes_status;
   end

   if isempty(chan_tick_status)
      chan_tick_status = 1;
      setting.chan_tick_status = chan_tick_status;
   end

   if isempty(bs_field)
      setting.bs_field = bs_field;
   end

   %------------------------- figure ----------------------

   if isempty(fig)			% if fig does not exist

      save_setting_status = 'on';
      erp_plot_pos = [];

      try
         load('pls_profile');
      catch
      end

      if ~isempty(erp_plot_pos) & strcmp(save_setting_status,'on')

         pos = erp_plot_pos;

      else

         w = 0.95;
         h = 0.85;
         x = (1-w)/2;
         y = (1-h)/2;

         pos = [x y w h];

      end

      xp = 0.0227273;
      yp = 0.0294118;
      wp = 1-2*xp;
      hp = 1-2*yp;

      pos_p = [xp yp wp hp];

      h0 = figure('unit','normal', ...
	'paperunit','normal', ...
	'paperorient','land', ...
	'paperposition',pos_p, ...
	'papertype','usletter', ...
        'numberTitle','off', ...
        'menubar', 'none', ...
        'toolbar','none', ...
        'name', fig_name, ...
	'user', fig_user, ...
	'color',[1 1 1], ...
	'buttondown','erp_plot_ui(''fig_bt_dn'');', ...
        'deleteFcn','erp_plot_ui(''delete_fig'');', ...
        'position', pos);
%	'renderer','opengl', ...

      if view_option == 2 | view_option == 4 | view_option == 5
         pos2 = pos;
         pos2(1) = pos2(1) + 0.02;
         pos2(2) = pos2(2) - 0.03;
%         set(h0,'name','Grand Average of ERP Amplitude', ...
%		'position', pos2);
         set(h0,'position', pos2);
      end

      %--------------------------- axes ----------------------

      x = 0;
      y = 0;
      w = 1;
      h = 1;

      pos = [x y w h];

      %  xlim & ylim are obtained thru testing, to make all channels
      %  fit in the figure while getting maximum result
      %
      ha = axes('parent',h0, ...
	'unit','normal', ...
	'color',[1 1 1], ...
	'fontsize', 11, ...
	'xlim',[0 1.1], ...
	'ylim',[-0.05 1.05], ...
	'ticklength',[0.002 1], ...
	'tickdir','out', ...
	'xtick', [], ...
	'ytick', [], ...
	'xaxislocation', 'top', ...
	'yaxislocation', 'left', ...
	'drawmode', 'fast', ...
	'visible','off', ...
	'position', pos);

%	'fontunit','normal', ...
%	'fontname','courier', ...
%	'fontsize',0.023, ...

      %--------------------------- menu ----------------------

      %  file
      %
      rri_file_menu(h0);

      %  edit
      %
      h_edit = uimenu('parent',h0, ...
           'visible','on', ...
           'label','&Edit');
      h2 = uimenu('parent', h_edit, ...
           'callback','erp_plot_ui(''select_rubber_chan'');', ...
           'label','&Select Electrodes with Rubberband');
      h2 = uimenu('parent', h_edit, ...
           'callback','erp_plot_ui(''select_all_chan'');', ...
           'label','Select &All Electrodes');
      h2 = uimenu('parent', h_edit, ...
           'callback','erp_plot_ui(''reset_all_chan'');', ...
           'label','&De-Select All Electrodes');
      hm_modify = uimenu('parent', h_edit, ...
           'separator', 'on', ...
           'callback','erp_plot_ui(''modify_datamat'');', ...
           'label','&Modify Datamat');

      if view_option ~= 1
         set(hm_modify,'visible','off');
      end

      %  zoom
      %

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -