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

📄 erp_plot_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 5 页
字号:
      h2 = uimenu('parent',h0, ...
           'userdata', 1, ...
           'callback','erp_plot_ui(''zoom'');', ...
           'label','&Zoom on');

      %  tool submenu
      %
      h_tool = uimenu('parent',h0, ...
           'visible','on', ...
           'label','&Tool');
      h2 = uimenu('parent',h_tool, ...
           'callback','erp_plot_ui(''option_menu'');', ...
           'label','&Display Options');
      hm_bs_option = uimenu('parent',h_tool, ...
           'visible','off', ...
           'callback','erp_plot_ui(''bs_option_menu'');', ...
           'label','&BootStrap Options');

      if view_option == 2

         h2 = uimenu('parent',h_tool, ...
           'separator', 'on', ...
           'callback', 'erp_plot_ui(''cond_mean'');', ...
           'label','Display Condition &Average');

         h2 = uimenu('parent',h_tool, ...
           'callback', 'erp_plot_ui(''cond_diff'');', ...
           'label','Display &Condition Difference');

      end

      %  view submenu
      %
      h_view = uimenu('parent',h0, ...
           'visible','on', ...
           'label','&View');

      hm_subj = uimenu('parent',h_view, ...		% subj
           'userdata', 0, ...
           'callback','erp_plot_ui(''toggle_subj'');', ...
           'visible', 'off', ...
           'label','Subject Amplitude');

      hm_avg = uimenu('parent',h_view, ...		% avg
           'userdata', 0, ...
           'callback','erp_plot_ui(''toggle_avg'');', ...
           'visible', 'off', ...
           'label','Average Amplitude');

      hm_corr = uimenu('parent',h_view, ...		% corr
           'userdata', 0, ...
           'callback','erp_plot_ui(''toggle_corr'');', ...
           'visible', 'off', ...
           'label','Spatiotemporal Correlation');

      hm_salience = uimenu('parent',h_view, ...		% salience
           'userdata', 0, ...
           'callback','erp_plot_ui(''toggle_salience'');', ...
           'visible', 'off', ...
           'label','Electrode Salience');

      hm_detail = uimenu('parent',h_view, ...
           'userdata', 0, ...
           'callback','erp_plot_ui(''toggle_detail'');', ...
           'label','Plot Detail');

      hm_eigen = [];
      hm_score = [];
      hm_brain = [];
      hm_canonical = [];
      hm_canonicalcorr = [];
      hm_contrast = [];

      if view_option == 3

         set(hm_subj, 'visible', 'on');
         set(hm_avg, 'visible', 'on');
%         set(hm_corr, 'visible', 'on');

         hm_eigen = uimenu('parent',h_view, ...
           'separator', 'on', ...
           'userdata', 0, ...
           'callback', 'erp_plot_ui(''toggle_eigen'');', ...
           'label','Plot Singular &Values');

         hm_score = uimenu('parent',h_view, ...
           'userdata', 0, ...
           'callback', 'erp_plot_ui(''toggle_score'');', ...
           'label','Plot &Design Scores');

         hm_brain = uimenu('parent',h_view, ...
           'userdata', 0, ...
           'callback', 'erp_plot_ui(''toggle_brain'');', ...
           'label','Plot &Scalp Scores');

         hm_canonical = uimenu('parent',h_view, ...
           'userdata', 0, ...
           'callback', 'erp_plot_ui(''toggle_canonical'');', ...
           'label','Plot Temporal Scores');

         hm_canonicalcorr = uimenu('parent',h_view, ...
           'userdata', 0, ...
           'callback', 'erp_plot_ui(''toggle_canonicalcorr'');', ...
           'label','Plot Temporal Correlations');

         hm_contrast = uimenu('parent',h_view, ...
	   'userdata', 0, ...
	   'callback', 'erp_plot_ui(''toggle_contrast'');', ...
	   'label','Contrasts Information');

      end

      hm_chan_name = uimenu('parent',h_view, ...
           'separator', 'on', ...
           'userdata', chan_name_status, ...
           'callback','erp_plot_ui(''toggle_chan_name'');', ...
           'label','Channel &Name');

      if chan_name_status
         set(hm_chan_name, 'check', 'on');
      else
         set(hm_chan_name, 'check', 'off');
      end

      hm_chan_axes = uimenu('parent',h_view, ...
           'userdata', chan_axes_status, ...
           'callback','erp_plot_ui(''toggle_chan_axes'');', ...
           'label','Channel &Axes');

      if chan_axes_status
         set(hm_chan_axes, 'check', 'on');
      else
         set(hm_chan_axes, 'check', 'off');
      end

      hm_chan_tick = uimenu('parent',h_view, ...
           'userdata', chan_tick_status, ...
           'callback','erp_plot_ui(''toggle_chan_tick'');', ...
           'label','Channel &Tickmark');

      if chan_tick_status
         set(hm_chan_tick, 'check', 'on');
      else
         set(hm_chan_tick, 'check', 'off');
      end

      %  legend
      %
      h_legend = uimenu('parent',h0, ...
           'label', '&Legend');
      hm_legend = uimenu('parent',h_legend, ...
           'userdata', 1, ...
           'callback','erp_plot_ui(''legend'');', ...
           'label','&Legend on');

      %  Help submenu
      %
      h_help = uimenu('parent',h0, ...
           'label', '&Help');

%           'callback','rri_helpfile_ui(''erp_result_hlp.txt'',''How to use ERP RESULT'');', ...
      h2 = uimenu('parent',h_help, ...
           'callback','web([''file:///'', which(''UserGuide.htm''), ''#_Toc128820742'']);', ...
	   'visible', 'on', ...
           'label', '&How to use this window?');

      h2 = uimenu('Parent',h_help, ...
           'Label', '&What''s new', ...
	   'Callback','rri_helpfile_ui(''whatsnew.txt'',''What''''s new'');', ...
           'Tag', 'New');
      h2 = uimenu('parent',h_help, ...
           'callBack', 'plsgui_version', ...
           'label', '&About this program');

   else				% if need to use the existing fig
      h0 = fig;
      ha = getappdata(h0,'ha');
      cla
      hm_bs_option = getappdata(h0,'hm_bs_option');
      hm_subj = getappdata(h0,'hm_subj');
      hm_avg = getappdata(h0,'hm_avg');
      hm_corr = getappdata(h0,'hm_corr');
      hm_detail = getappdata(h0,'hm_detail');
      hm_eigen = getappdata(h0,'hm_eigen');
      hm_score = getappdata(h0,'hm_score');
      hm_brain = getappdata(h0,'hm_brain');
      hm_canonical = getappdata(h0,'hm_canonical');
      hm_canonicalcorr = getappdata(h0,'hm_canonicalcorr');
      hm_contrast = getappdata(h0,'hm_contrast');
      hm_chan_name = getappdata(h0,'hm_chan_name');
      hm_chan_axes = getappdata(h0,'hm_chan_axes');
      hm_chan_tick = getappdata(h0,'hm_chan_tick');
      hm_legend = getappdata(h0,'hm_legend');
   end				% if empty(fig)

   setappdata(h0,'ha',ha);			% axes
   setappdata(h0,'hm_bs_option',hm_bs_option);	% bootstrap opton
   setappdata(h0,'hm_subj',hm_subj);		% open group subject window
   setappdata(h0,'hm_avg',hm_avg);		% open grand average window
   setappdata(h0,'hm_corr',hm_corr);		% open behavior corr window
   setappdata(h0,'hm_detail',hm_detail);	% open detail plot window
   setappdata(h0,'hm_eigen',hm_eigen);		% open eigen value window
   setappdata(h0,'hm_score',hm_score);		% open score window
   setappdata(h0,'hm_brain',hm_brain);		% open brain window
   setappdata(h0,'hm_canonical',hm_canonical);	% open canonical scores window
   setappdata(h0,'hm_canonicalcorr',hm_canonicalcorr);	% open canonical corr window
   setappdata(h0,'hm_contrast',hm_contrast);	% open contrast window
   setappdata(h0,'hm_chan_name',hm_chan_name);	% channel name
   setappdata(h0,'hm_chan_axes',hm_chan_axes);	% channel axes
   setappdata(h0,'hm_chan_tick',hm_chan_tick);	% channel tickmark
   setappdata(h0,'hm_legend',hm_legend);	% legend

   % ---------  start to pre-process ERP data below  -------------

   avg_name = [];
   wave_name = [];
   wave_order = [];
   bs_name = [];
   selected_bs = [];
   selected_wave = [];		% based on selected_conditions & selected_subj
   selected_wave_info = [];	% [Condition#, subject#]

   selected_subjects = [];	% init
   selected_conditions = [];
   session_info = [];

   try
      load(datamat_file);

      if exist('datafile','var')
         rri_changepath('erpdata');
         load(datafile);
      end

      if ~exist('system','var')
         system.class = 1;
         system.type = 1;
      end
   catch
      msg = ['ERROR: Could not open file ' datamat_file];
      msgbox(msg,'ERROR','modal');
      return;
   end

   if ~exist('cond_selection','var') & exist('common_conditions','var')
      cond_selection = ones(1, sum(common_conditions));
   end

   if (~exist('bscan','var') | isempty(bscan) ) & exist('common_conditions','var')
      bscan = 1:sum(common_conditions);
   elseif (~exist('bscan','var') | isempty(bscan) )
      bscan = 1:sum(selected_conditions);
   end

   num_group = [];

   switch view_option		% what to plot
      case {1}				% subj

         rri_changepath('erpdatamat');

         if ~isfield(session_info,'system')
            system.class = 1;
            system.type = 1;
         else
            system = session_info.system;
         end

         chan_mask = session_info.chan_order;

         avg_name = session_info.condition;

         %  timepoint_start means the position of start_point
         %  respect to the position of prestim.
         %  while start_timepoint means the position of start_point
         %  respect to 0
         %
         timepoint_start = round((time_info.start_time - time_info.prestim) / time_info.digit_interval +1);
         timepoint_end = round((time_info.end_time - time_info.prestim) / time_info.digit_interval +1);

         %  Chop out the un_selected timepoints
         %
         datamat = datamat(timepoint_start:timepoint_end, :, :, :);
         
         wave_amplitude = reshape(datamat, ...
		[round(time_info.timepoint), ...
		 session_info.num_channels, ...
		 session_info.num_subjects * session_info.num_conditions]);

         %  Grand average for the selected subjects only
         %
         datamat = datamat(:,:,find(selected_subjects),:);
         datamat = mean(datamat, 3);

         avg_amplitude = reshape(datamat, ...
		[round(time_info.timepoint), ...
		 session_info.num_channels, ...
		 session_info.num_conditions]);

         a = 2;				% total increase in order (exclude 'none')
         p = 1;				% selected cond increase in order
         for i=find(selected_conditions)
            q = 1;			% selected subj increase in order
            for j=find(selected_subjects)
               idx = (i-1)*session_info.num_subjects + j;
               selected_wave = [selected_wave idx];
               selected_wave_info(idx, 1) = i;
               selected_wave_info(idx, 2) = j;
               name_str = [session_info.subj_name{j},' in "',avg_name{i}, '"'];
               wave_name{idx} = name_str;
               wave_order(a-1,:) = [a, q, p];
               q = q + 1;
               a = a + 1;
            end
            p = p + 1;
         end

         rescale = 0;
         setting.rescale = rescale;

      case {2}				% average

         rri_changepath('erpresult');

         chan_mask = chan_order(find(common_channels));

         time_info = common_time_info;

         ti = round(time_info.timepoint);
         ch = sum(common_channels);
         lv = size(salience,2);

         newdata_lst = erp_get_common(datamat_files, 1, 1, cond_selection);
         num_group = length(newdata_lst);
         num_cond = sum(common_conditions);

         org_wave_amplitude = erp_datamat2datacub(newdata_lst, ...
		common_channels, common_conditions, mean_wave_list);

         tmp = [ones(1,sum(common_conditions))]' * [1:num_group];
         wave_order = [[1:num_group*num_cond]'+1 tmp(:) [repmat([1:sum(common_conditions)], [1 num_group])]'];

         [dim1 dim2 dim3] = size(org_wave_amplitude);

         wave_amplitude = org_wave_amplitude;
         if ~isempty(cond_couple_lst)
            for i = 1:size(cond_couple_lst,1)
               wave_amplitude(:,:,dim3+i) = ...
		   org_wave_amplitude(:,:,cond_couple_lst(i,1)) - ...
		   org_wave_amplitude(:,:,cond_couple_lst(i,2));
            end
         end

         selected_channels = ones(1,sum(common_channels));
         org_selected_wave = 1:num_cond*num_group;

         selected_wave = [org_selected_wave ...
		length(org_selected_wave)+[1:length(mean_wave_name)] ...
		length(org_selected_wave)+length(mean_wave_name)+[1:size(cond_couple_lst,1)]];
		%  append

         selected_bs = 1:lv;

         %  display bootstrap result if there is one
         %
         if exist('boot_result','var') & ~isempty(boot_result)

            %  get bootstrap ratio from boot_result
            %
            bs_ratio = boot_result.compare;
            bsr = bs_ratio;

            %  initialize bootstrap field
            %
            if isempty(bs_field)
               bs_field = erp_bs_option_ui('set_bs_fields',bsr);
               setting.bs_field = bs_field;
            end

            %  set amplitude to 1 if above threshold, 0 otherwise
            %
            for i = 1:lv
               too_large = find(bsr > (bs_field{i}.max_ratio));
               bsr(too_large) = bs_field{i}.max_ratio;

               too_small = find(bsr < (bs_field{i}.min_ratio));
               bsr(too_small) = bs_field{i}.min_ratio;

               bs_amplitude(:,i) = (abs(bsr(:,i)) >= (bs_field{i}.thresh));
            end

            %  selected_channels & selected_wave will be the same
            %
            bs_amplitude = reshape(bs_amplitude, [ti, ch, lv]);

            %  enable bootstrap option menu
            %
            set(hm_bs_option, 'visible', 'on');

         end    % exist('boot_result')

         %  condition name
         %
         org_wave_name = cond_name(find(common_conditions));
         org_wave_name = repmat(org_wave_name, [1, num_group]);

         g = 1;
         for i = 1:length(org_wave_name)
            org_wave_name{i} = [org_wave_name{i}, ' in group ', num2str(g)];
            if mod(i, num_cond) == 0
               g = g + 1;
            end
         end

         wave_name = [org_wave_name, mean_wave_name];

         %  couple name
         %
         couple_name = cell(1,size(cond_couple_lst,1));

         for i = 1:size(cond_couple_lst,1)
            couple_name{i} = ...
		[wave_name{cond_couple_lst(i,1)} ' - ' wave_name{cond_couple_lst(i,2)}];
%		['cond' num2str(cond_couple_lst(i,1)) ' - cond' num2str(cond_couple_lst(i,2))];
         end

         wave_name = [wave_name, couple_name];

         bs_name = [];

⌨️ 快捷键说明

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