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

📄 erp_plot_brain_scores.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 3 页
字号:

   rri_changepath('erpresult');

   grp_rows = [];
   num_groups = length(datamat_files);
   selected_conditions1 = common_conditions;

   if exist('bscan','var') & ~isempty(bscan)
      selected_conditions = find(selected_conditions1);
      selected_conditions = selected_conditions(bscan);
      cond_selection = zeros(1,length(selected_conditions1));
      cond_selection(selected_conditions) = 1;
   end

   selected_conditions = cond_selection;

   for i=1:num_groups

      load(datamat_files{i}, 'selected_subjects', ...	% 'selected_conditions',
		'session_info', 'session_file');	% load the condition from session profile

      rri_changepath('erpdatamat');

      grp_rows = [grp_rows, sum(selected_subjects)*sum(selected_conditions)];

   end

%   conditions = session_info.condition(find(selected_conditions));
   conditions = session_info.condition;
   setappdata(gcf, 'grp_rows', grp_rows);

   return;					% load_pls_brainscores


%--------------------------------------------------------------------------
%
function  status = get_brain_scores

   status = 0;

   h = findobj(gcf,'Tag','STDatamatPopup');
   popup_string = get(h,'String');
   selected_idx = get(h,'Value');
   selected_data = popup_string{selected_idx};

   last_datamat = getappdata(gcf,'PlottedDatamat');

   % if (isempty(last_datamat) | strcmp(last_datamat,selected_data) == 0)
   if(1)
       setappdata(gcf,'PlottedDatamat',selected_data);
       set(findobj(gcf,'Tag','MessageLine'),'String','');
   else
       status = 2;
       return;
   end;

   datamat_file = getappdata(gcf,'datamat_filename');
   datamat_file = datamat_file{selected_idx}.fullname;

   load(datamat_file, 'selected_conditions', ...
		'session_info', 'session_file');	% load the condition from session profile

   rri_changepath('erpdatamat');

   setappdata(gcf,'session_info',session_info);
%   setappdata(gcf,'selected_conditions',selected_conditions);
   setappdata(gcf,'selected_idx',selected_idx);

   status = 1;

   return;                                              % get_brain_scores


%--------------------------------------------------------------------------
%
function  plot_brain_scores(choice)

   status = get_brain_scores;

   if (status ~= 1);
      return;
   end;

   lv = getappdata(gcf, 'CurrLVState');

   detail_state = getappdata(gcf,'PlotDetailState');
   allerr_state = getappdata(gcf,'PlotAllerrState');
   dlv_state = getappdata(gcf,'PlotDLVState');

   brainscores = getappdata(gcf, 'brainscores');
   behavdata = getappdata(gcf, 'behavdata');
   behavname = getappdata(gcf, 'behavname');
   selected_conditions = getappdata(gcf, 'selected_conditions');
   session_info = getappdata(gcf, 'session_info');
   grp_rows = getappdata(gcf,'grp_rows');
   selected_idx = getappdata(gcf,'selected_idx');
   datamat_filename = getappdata(gcf,'datamat_filename');
   selected_subjects = datamat_filename{selected_idx}.selected_subjects;

   [r c]=size(brainscores);
   numscans = sum(selected_conditions);
   numbehav = size(behavdata, 2);
%   numsubj = session_info.num_subjects;
   num_subj_lst = getappdata(gcf,'num_subj_lst');
   numsubj = num_subj_lst(selected_idx);
   numlvs = c;
   lv = find(lv);

   for behav=1:numbehav

      first = sum(grp_rows(1:selected_idx))-grp_rows(selected_idx)+1;
      last = first+numsubj-1;

      for scan=1:numscans

         p1 = polyfit(behavdata(first:last,behav), ...
		      brainscores(first:last,lv),  1);            
         linc_wave(:,behav,scan) = polyval(p1, behavdata(first:last,behav));
         brain_wave(:,1,scan) = brainscores(first:last,lv);
         behav_wave(:,behav,scan) = behavdata(first:last,behav);

         strong = corrcoef(behavdata(first:last,behav), ...
			   brainscores(first:last,lv)  );
         strong_r(1,behav,scan) = strong(1,2);

         first = first +numsubj;	%scans are stacked, so increment               
         last = last +numsubj;

      end
   end

   first = numscans*numbehav*(selected_idx-1)+1;
   last = first+numscans*numbehav-1;

   boot_result = getappdata(gcf,'boot_result');
   lvcorrs = getappdata(gcf,'lvcorrs');

   if isempty(boot_result)
%      set(findobj('tag','BrainMenu'),'visible','off');
%      set(findobj('tag','ErrorMenu'),'visible','off');
      plotted_data.orig_corr = lvcorrs(first:last,lv);
      plotted_data.ulcorr = [];
      plotted_data.llcorr = lvcorrs(first:last,lv);
   else
      plotted_data.orig_corr = boot_result.orig_corr(first:last,lv);
      plotted_data.ulcorr = boot_result.ulcorr(first:last,lv);
      plotted_data.llcorr = boot_result.llcorr(first:last,lv);
   end

   plotted_data.linc_wave = linc_wave;
   plotted_data.brain_wave = brain_wave;
   plotted_data.behav_wave = behav_wave;
   plotted_data.behavname = behavname;
   plotted_data.strong_r = strong_r;

   condition.cond_name = session_info.condition(find(selected_conditions));
   tmp = session_info.subj_name;
   condition.subj_name = tmp(find(selected_subjects));

   h = findobj(gcf,'Tag','PlotButton');
   if strcmp(lower(get(h,'Enable')),'off'),  return; end;

   % generate the plots
   %
   plot_cond_idx = [1:numscans];

   plot_dims = getappdata(gcf,'PlotDims');

   if isempty(plot_dims) 

       if (numscans < 1)
         num_rows = numscans;
       else
         num_rows = 1;
       end;
       if (numbehav < 1),
         num_cols = numbehav;
       else
         num_cols = 1;
       end;

       plot_dims = [num_rows num_cols];

   end;

   axes_margin = [.25 .05 .18 .05];

   pet_detail_hdl = [];
   pet_allerr_hdl = [];
   pet_dlv_hdl = [];
   h0 = gcf;

   pet_plot_cond_stim_ui('STARTUP', plotted_data, condition,  ...
		axes_margin, plot_dims, plot_cond_idx);

   if detail_state
      pet_detail_hdl = ...
		pet_plot_detail_stim_ui('STARTUP', plotted_data, condition,  ...
		axes_margin, plot_dims, plot_cond_idx, 'Scalp Scores');

      setappdata(pet_detail_hdl,'main_fig',h0);
      setappdata(h0,'pet_detail_hdl',pet_detail_hdl);

      pet_allerr_hdl = getappdata(h0,'pet_allerr_hdl');
      if ~isempty(pet_allerr_hdl) & ishandle(pet_allerr_hdl)
         setappdata(pet_detail_hdl,'pet_allerr_hdl',pet_allerr_hdl);
      end

      pet_dlv_hdl = getappdata(h0,'pet_dlv_hdl');
      if ~isempty(pet_dlv_hdl) & ishandle(pet_dlv_hdl)
         setappdata(pet_detail_hdl,'pet_dlv_hdl',pet_dlv_hdl);
      end
   end

   if allerr_state
      pet_allerr_hdl = pet_plot_allerr;

      setappdata(pet_allerr_hdl,'main_fig',h0);
      setappdata(h0,'pet_allerr_hdl',pet_allerr_hdl);

      pet_detail_hdl = getappdata(h0,'pet_detail_hdl');
      if ~isempty(pet_detail_hdl) & ishandle(pet_detail_hdl)
         setappdata(pet_allerr_hdl,'pet_detail_hdl',pet_detail_hdl);
      end

      pet_dlv_hdl = getappdata(h0,'pet_dlv_hdl');
      if ~isempty(pet_dlv_hdl) & ishandle(pet_dlv_hdl)
         setappdata(pet_allerr_hdl,'pet_dlv_hdl',pet_dlv_hdl);
      end
   end

   if dlv_state
      pet_dlv_hdl = pet_plot_behavlv;

      setappdata(pet_dlv_hdl,'main_fig',h0);
      setappdata(h0,'pet_dlv_hdl',pet_dlv_hdl);

      pet_detail_hdl = getappdata(h0,'pet_detail_hdl');
      if ~isempty(pet_detail_hdl) & ishandle(pet_detail_hdl)
         setappdata(pet_dlv_hdl,'pet_detail_hdl',pet_detail_hdl);
      end

      pet_allerr_hdl = getappdata(h0,'pet_allerr_hdl');
      if ~isempty(pet_allerr_hdl) & ishandle(pet_allerr_hdl)
         setappdata(pet_dlv_hdl,'pet_allerr_hdl',pet_allerr_hdl);
      end
   end

   if exist('choice','var') & strcmp(choice,'detail') & detail_state
      figure(pet_detail_hdl);
   elseif exist('choice','var') & strcmp(choice,'allerr') & allerr_state
      figure(pet_allerr_hdl);
   elseif exist('choice','var') & strcmp(choice,'dlv') & dlv_state
      figure(pet_dlv_hdl);
   else
      figure(h0);
   end

   setappdata(gcf,'ERP_PLOT_BS_ACTIVE',1);
   setappdata(gcf,'PLS_BS_PLOTTED_DATA',plotted_data);
   setappdata(gcf,'PLS_BS_PLOTTED_CONDITON',condition);
   setappdata(gcbf,'pet_detail_hdl',pet_detail_hdl);
   setappdata(gcbf,'pet_allerr_hdl',pet_allerr_hdl);
   setappdata(gcbf,'pet_dlv_hdl',pet_dlv_hdl);

   return;


%--------------------------------------------------------------------------
%
function  ToggleBrain

   brain_state = getappdata(gcf,'PlotBrainState');

   switch (brain_state)
      case {0}

         m_hdl = findobj(gcf,'Tag','BrainMenu');
         set(m_hdl,'Label','Hide Brain Scores Plot');
         setappdata(gcf,'PlotBrainState',1);

         m_hdl = findobj(gcf,'Tag','ErrorMenu');
         set(m_hdl,'Label','Show Correlation Plot');
         setappdata(gcf,'PlotErrorState',0);

         set(findobj('tag','ChgPlotDims'),'visible','on');

         m_hdl = findobj(gcf,'Tag','LegendMenu');
         set(m_hdl,'Label','&Show Legend','userdata',0,'visible','off');

      case {1}

         m_hdl = findobj(gcf,'Tag','BrainMenu');
         set(m_hdl,'Label','Show Scalp Scores Plot');
         setappdata(gcf,'PlotBrainState',0);

         m_hdl = findobj(gcf,'Tag','ErrorMenu');
         set(m_hdl,'Label','Hide Correlation Plot');
         setappdata(gcf,'PlotErrorState',1);

         set(findobj('tag','ChgPlotDims'),'visible','off');

         m_hdl = findobj(gcf,'Tag','LegendMenu');
         set(m_hdl,'Label','&Hide Legend','userdata',1,'visible','on');

   end

   plot_brain_scores;

   return;


%--------------------------------------------------------------------------
%
function  ToggleError

   error_state = getappdata(gcf,'PlotErrorState');

   switch (error_state)
      case {1}

         m_hdl = findobj(gcf,'Tag','BrainMenu');
         set(m_hdl,'Label','Hide Brain Scores Plot');
         setappdata(gcf,'PlotBrainState',1);

         m_hdl = findobj(gcf,'Tag','ErrorMenu');
         set(m_hdl,'Label','Show Correlation Plot');
         setappdata(gcf,'PlotErrorState',0);

         set(findobj('tag','ChgPlotDims'),'visible','on');

         m_hdl = findobj(gcf,'Tag','LegendMenu');
         set(m_hdl,'Label','&Show Legend','userdata',0,'visible','off');

      case {0}

         m_hdl = findobj(gcf,'Tag','BrainMenu');
         set(m_hdl,'Label','Show Scalp Scores Plot');
         setappdata(gcf,'PlotBrainState',0);

         m_hdl = findobj(gcf,'Tag','ErrorMenu');
         set(m_hdl,'Label','Hide Correlation Plot');
         setappdata(gcf,'PlotErrorState',1);

         set(findobj('tag','ChgPlotDims'),'visible','off');

         m_hdl = findobj(gcf,'Tag','LegendMenu');
         set(m_hdl,'Label','&Hide Legend','userdata',1,'visible','on');

   end

   plot_brain_scores;

   return;


%--------------------------------------------------------------------------
%
function  ToggleDetail

   detail_state = getappdata(gcf,'PlotDetailState');

   switch (detail_state)
      case {1}

         m_hdl = findobj(gcf,'Tag','DetailMenu');
         set(m_hdl,'Label','Show Scalp Scores &Overview');
         setappdata(gcf,'PlotDetailState',0);

         pet_detail_hdl = getappdata(gcf,'pet_detail_hdl');
         if exist('pet_detail_hdl','var') & ishandle(pet_detail_hdl)
            try
               delete(pet_detail_hdl);
            catch
            end
         end

      case {0}

         m_hdl = findobj(gcf,'Tag','DetailMenu');
         set(m_hdl,'Label','Hide Scalp Scores &Overview');
         setappdata(gcf,'PlotDetailState',1);

         plot_brain_scores('detail');

   end

   return;


%----------------------------------------------------------------------------
%
function num_cond = light_get_common(datamat_files)

   common_conditions = [];
   num_files = length(datamat_files);

   for i=1:num_files

      load(datamat_files{i}, 'selected_conditions');

      %  initially, common_conditions is empty, init it with zero array
      %
      if isempty(common_conditions)
         common_conditions = zeros(1,length(selected_conditions));
      end

      common_conditions = common_conditions + selected_conditions;

   end

   %  find only the overlap parts of common conditions
   %
   idx = find(common_conditions == num_files);
   common_conditions = zeros(1,length(selected_conditions));
   common_conditions(idx) = 1;

   num_cond = sum(common_conditions);

   return;


%--------------------------------------------------------------------------
%
function  ToggleDLV

   dlv_state = getappdata(gcf,'PlotDLVState');

   switch (dlv_state)
      case {1}

         m_hdl = findobj(gcf,'Tag','DLVMenu');
         set(m_hdl,'Label','Show Behavior &LV Overview');
         setappdata(gcf,'PlotDLVState',0);

         pet_dlv_hdl = getappdata(gcf,'pet_dlv_hdl');
         if exist('pet_dlv_hdl','var') & ishandle(pet_dlv_hdl)
            try
               delete(pet_dlv_hdl);
            catch
            end
         end

      case {0}

         m_hdl = findobj(gcf,'Tag','DLVMenu');
         set(m_hdl,'Label','Hide Behavior &LV Overview');
         setappdata(gcf,'PlotDLVState',1);

         plot_brain_scores('dlv');

   end

   return;


%--------------------------------------------------------------------------
%
function  ToggleAllerr

   allerr_state = getappdata(gcf,'PlotAllerrState');

   switch (allerr_state)
      case {1}

         m_hdl = findobj(gcf,'Tag','AllerrMenu');
         set(m_hdl,'Label','Show &Correlation Overview');
         setappdata(gcf,'PlotAllerrState',0);

         pet_allerr_hdl = getappdata(gcf,'pet_allerr_hdl');
         if exist('pet_allerr_hdl','var') & ishandle(pet_allerr_hdl)
            try
               delete(pet_allerr_hdl);
            catch
            end
         end

      case {0}

         m_hdl = findobj(gcf,'Tag','AllerrMenu');
         set(m_hdl,'Label','Hide &Correlation Overview');
         setappdata(gcf,'PlotAllerrState',1);

         plot_brain_scores('allerr');

   end

   return;

⌨️ 快捷键说明

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