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

📄 pet_plot_brain_scores.m

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

         for g = 1:num_groups
            orig_corr = [orig_corr; boot_result.orig_corr((g-1)*k+(g-1)*kk*t+k+1:(g-1)*k+(g-1)*kk*t+k+kk*t,:)];
            ulcorr = [ulcorr; boot_result.ulcorr((g-1)*k+(g-1)*kk*t+k+1:(g-1)*k+(g-1)*kk*t+k+kk*t,:)];
            llcorr = [llcorr; boot_result.llcorr((g-1)*k+(g-1)*kk*t+k+1:(g-1)*k+(g-1)*kk*t+k+kk*t,:)];
         end

         boot_result.orig_corr = orig_corr;
         boot_result.ulcorr = ulcorr;
         boot_result.llcorr = llcorr;
      end
   end

   rri_changepath('petresult');

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

   for i=1:num_groups

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

      num_conditions = session_info.num_conditions;

      if isempty(cond_selection)
         num_cond = num_conditions;
         cond_selection = ones(1,num_cond);
      else
         num_cond = sum(cond_selection);
      end

      selected_conditions = find(cond_selection);
      grp_rows = [grp_rows,session_info.num_subjects*kk];

   end

   if exist('bscan','var') & ~isempty(bscan)
      num_cond_lst = kk * ones(1, length(num_cond_lst));
      selected_conditions = selected_conditions(bscan);
      cond_selection = zeros(1,length(cond_selection));
      cond_selection(selected_conditions) = 1;
   end

%   conditions = session_info.condition(find(cond_selection));
   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, 'session_info');	% load the condition from session profile

   cond_selection = getappdata(gcf,'cond_selection');

   if(isempty(cond_selection))
      selected_conditions = 1:session_info.num_conditions;
   else
      selected_conditions = find(cond_selection);
   end

   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');

   [r c]=size(brainscores);
   numscans = length(selected_conditions);
   numbehav = size(behavdata, 2);
   numsubj = session_info.num_subjects;
   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));
% wrong labelling 

   condition.cond_name = session_info.condition(selected_conditions);
   condition.subj_name = session_info.subj_name;

   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, 'Brain 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,'PET_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 Brain 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 Brain 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 &Brain 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 &Brain Scores Overview');
         setappdata(gcf,'PlotDetailState',1);

         plot_brain_scores('detail');

   end

   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 + -