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

📄 erp_plot_scores_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 4 页
字号:
   s_pos = get(h,'Position');
   s_pos(2) = v_pos(end);
   s_pos(4) = v_pos(1) - v_pos(end) + row_height;
   set(h,'Position',s_pos);
 

   setappdata(gcf,'LV_hlist',lv_hdls);
   setappdata(gcf,'NumLVRows',rows);

   return;						% SetupLVButtonRows


% --------------------------------------------------------------------
function  DisplayLVButtons()

   curr_lv_state = getappdata(gcf,'CurrLVState');
   top_lv_button = getappdata(gcf,'TopLVButton');
   lv_hdls = getappdata(gcf,'LV_hlist');
   rows = getappdata(gcf,'NumLVRows');

   num_lvs = length(curr_lv_state);

   lv_idx = top_lv_button;
   for i=1:rows,
       l_hdl = lv_hdls(i);
       if (lv_idx <= num_lvs),
          set(lv_hdls(i),'String',sprintf('LV #%d',lv_idx), ...
			 'Value',curr_lv_state(lv_idx), ...
	                 'Visible','on', ...
                         'Userdata',i);
          lv_idx = lv_idx + 1;
       else
          set(lv_hdls(i),'String','','Visible','off');
       end
   end;

   if (top_lv_button ~= 1) | (num_lvs > rows)
      set(findobj(gcf,'Tag','LVButtonSlider'),'Visible','on');
   else
      set(findobj(gcf,'Tag','LVButtonSlider'),'Visible','off');
   end;

   return;						% DisplayLVButtons


%----------------------------------------------------------------------------
function MoveSlider()

   slider_hdl = findobj(gcf,'Tag','LVButtonSlider');
   curr_value = round(get(slider_hdl,'Value'));
   total_rows = round(get(slider_hdl,'Max'));

   top_lv_button = total_rows - curr_value + 1;

   setappdata(gcf,'TopLVButton',top_lv_button);

   DisplayLVButtons;

   return;                                              % MoveSlider


% --------------------------------------------------------------------

function PlotScalpDesignScores

   if (getappdata(gcf,'PlotScalpDesignState') == 0)
      return;
   end;

   s = getappdata(gcf,'s');
   cb = erp_per(s);
   perm_result = getappdata(gcf,'perm_result');
   subj_select_lst = getappdata(gcf, 'subj_select_lst');
   scalpscores = getappdata(gcf, 'scalpscores');
   designscores = getappdata(gcf, 'designscores');
   conditions = getappdata(gcf, 'conditions');
   num_cond_lst = getappdata(gcf, 'num_cond_lst');
   num_subj_lst = getappdata(gcf, 'num_subj_lst');

   if (getappdata(gcf,'PlotDesignState') == 1),
      ax_hdl = getappdata(gcf,'bottom_axes');
   else
      ax_hdl = getappdata(gcf,'main_axes');
   end;

   set(ax_hdl, ...
	'buttondown','erp_plot_scores_ui(''fig_bt_dn'');', ...
	'userdata', 'PlotScalpDesignScores');

   lv_state = getappdata(gcf,'CurrLVState');
   lv_idx = find(lv_state == 1);
   num_conds = num_cond_lst(1);
   num_grp = getappdata(gcf, 'num_grp');

   num_in_grp = [0 num_cond_lst.*num_subj_lst];

   color_code =[ 'bo';'rx';'g+';'m*';'bs';'rd';'g^';'m<';'bp';'r>'; ...
                  'gh';'mv';'ro';'gx';'m+';'b*';'rs';'gd';'m^';'b<'];

   % need more color
   %
   if num_conds > size(color_code,1)

      tmp = [];

      for i=1:ceil(num_conds/size(color_code,1))
         tmp = [tmp; color_code];
      end

      color_code = tmp;

   end

   min_x = min(designscores(:));	max_x = max(designscores(:));
   min_y = min(scalpscores(:));		max_y = max(scalpscores(:));
   margin_x = abs((max_x - min_x) / 20);
   margin_y = abs((max_y - min_y) / 20);

   axes(ax_hdl);
   cla; grid off; hold on;

 for grp_idx = 1:num_grp

   num_subjs = num_subj_lst(grp_idx);
   first = sum(num_in_grp(1:grp_idx)) + 1;
   last = sum(num_in_grp(1:(grp_idx+1)));
   tmp_d_scores = designscores(first:last,:);
   tmp_b_scores = scalpscores(first:last,:);

   for n=1:num_subjs
      for k=1:num_conds
         j = sum(num_in_grp(1:grp_idx)) + (k-1) * num_subjs + n;
         score_hdl(grp_idx,n,k) = plot(designscores(j,lv_idx), ...
		scalpscores(j,lv_idx), ...
		color_code(k,:), ...
		'buttondown','erp_plot_scores_ui(''select_subj'');', ...
		'userdata', [grp_idx, n]);

         if ~subj_select_lst{grp_idx}(n)
            set(score_hdl(grp_idx,n,k), 'visible', 'off');
         end
      end
   end
 end

   setappdata(gcf, 'score_hdl', score_hdl);

   set(ax_hdl, 'xtickmode','auto',  'xticklabelmode','auto');
   axis([min_x-margin_x,max_x+margin_x,min_y-margin_y,max_y+margin_y]);
   hold off;

   l_hdl = [];

   if ~isempty(conditions),

      % remove the old legend to avoid the bug in the MATLAB5
      old_legend = getappdata(gcf,'LegendHdl');
      if ~isempty(old_legend),
        try
          delete(old_legend{1});
        catch
        end;
      end;

      % create a new legend, and save the handles
      [l_hdl, o_hdl] = legend(conditions, 0);
      legend_txt(o_hdl);
      set(l_hdl,'color',[0.9 1 0.9]);
      setappdata(gcf,'LegendHdl',[{l_hdl} {o_hdl}]);

      legend_state = get(findobj(gcf,'Tag','LegendMenu'),'Userdata');
      if (legend_state == 1),
	 DisplayLegend('on');
      else
	 DisplayLegend('off');
      end;

   else

      setappdata(gcf,'LegendHdl',[]);

   end;

   if(getappdata(gcf, 'is_design_plot'))
      xlabel('Design Scores');
   else
      xlabel('Behavior Scores');
   end

   ylabel('Scalp Scores');
   title('');

   try
      txtbox_hdl = getappdata(gcf,'txtbox_hdl');
      delete(txtbox_hdl);                           % clear rri_txtbox
   catch
   end

   if (getappdata(gcf,'PlotDesignState') == 1) | isempty(perm_result)
      return;
   else
      title(sprintf('LV %d:  %.2f%% crossblock,  p < %.3f', lv_idx, 100*cb(lv_idx), perm_result.sprob(lv_idx)));
   end

   return;					% PlotScalpDesignScores


%---------------------------------------------------------------------------

function PlotDesignScores

   if (getappdata(gcf,'PlotDesignState') == 0),
      return;
   end;

   s = getappdata(gcf,'s');
   cb = erp_per(s);
   perm_result = getappdata(gcf,'perm_result');
   designscores = getappdata(gcf,'designscores');
   conditions = getappdata(gcf,'conditions');
   num_cond_lst = getappdata(gcf, 'num_cond_lst');
   num_subj_lst = getappdata(gcf, 'num_subj_lst');

   if (getappdata(gcf,'PlotScalpDesignState') == 1),
      ax_hdl = getappdata(gcf,'top_axes');
   else
      ax_hdl = getappdata(gcf,'main_axes');
   end;

   axes(ax_hdl);
   cla;hold on;

   lv_state = getappdata(gcf,'CurrLVState');
   lv_idx = find(lv_state == 1);
   num_conds = num_cond_lst(1);

   num_in_grp = [0 num_cond_lst.*num_subj_lst];

   num_grp = getappdata(gcf,'num_grp');
   grp_d_scores = [];

   for grp_idx = 1:num_grp

      num_subjs = num_subj_lst(grp_idx);
      first = sum(num_in_grp(1:grp_idx)) + 1;
      last = sum(num_in_grp(1:(grp_idx+1)));
      tmp_d_scores = designscores(first:last,:);

      mask = [];

      for k = 1:num_conds
         mask = [mask,num_subj_lst(grp_idx)*(k-1)+1];
      end

      grp_d_scores = [grp_d_scores; tmp_d_scores(mask,:)];

   end

   min_x = 0.5;				max_x = size(grp_d_scores, 1)+0.5;
   min_y = min(grp_d_scores(:));	max_y = max(grp_d_scores(:));
   margin_x = abs((max_x - min_x) / 20);
   margin_y = abs((max_y - min_y) / 20);

   load('rri_color_code');

   for g=1:num_grp
      for k = 1:num_conds
         bar_hdl = bar((g-1)*num_conds + k,grp_d_scores((g-1)*num_conds + k,lv_idx));
         set(bar_hdl,'facecolor',color_code(k,:));
      end
   end

   set(ax_hdl,'xtick',([1:num_grp] - 1)*num_conds + 0.5);
   set(ax_hdl,'xticklabel',1:num_grp);

   hold off;

   axis([min_x,max_x,min_y-margin_y,max_y+margin_y]);

   set(ax_hdl, 'userdata', 'PlotDesignScores');
   set(ax_hdl,'tickdir','out','ticklength', [0.005 0.005], ...
	'box','on');

   conditions = getappdata(gcf, 'conditions');

   if ~isempty(conditions),

      % remove the old legend to avoid the bug in the MATLAB5
      old_legend = getappdata(gcf,'LegendHdl2');
      if ~isempty(old_legend),
        try
          delete(old_legend{1});
        catch
        end;
      end;

      % create a new legend, and save the handles
      [l_hdl, o_hdl] = legend(conditions, 0);
      legend_txt(o_hdl);
      set(l_hdl,'color',[0.9 1 0.9]);
      setappdata(gcf,'LegendHdl2',[{l_hdl} {o_hdl}]);

      legend_state = get(findobj(gcf,'Tag','LegendMenu'),'Userdata');
      if (legend_state == 1),
	 DisplayLegend('on');
      else
	 DisplayLegend('off');
      end;

   else

      setappdata(gcf,'LegendHdl2',[]);

   end;

   xlabel('Groups');

   if(getappdata(gcf, 'is_design_plot'))
      ylabel('Design Scores');
   else
      ylabel('Behavior Scores');
   end

   title('');
   grid on;

   try
      txtbox_hdl = getappdata(gcf,'txtbox_hdl');
      delete(txtbox_hdl);                           % clear rri_txtbox
   catch
   end

   if isempty(perm_result)
      return;
   else
      title(sprintf('LV %d:  %.2f%% crossblock,  p < %.3f', lv_idx, 100*cb(lv_idx), perm_result.sprob(lv_idx)));
   end

   return;                                              % PlotDesignScores


%---------------------------------------------------------------------------

function PlotDesignLV

   if (getappdata(gcf,'PlotDesignLVState') == 0)
      return;
   end;

   s = getappdata(gcf,'s');
   cb = erp_per(s);
   perm_result = getappdata(gcf,'perm_result');
   designlv = getappdata(gcf,'designlv');

   num_cond_lst = getappdata(gcf, 'num_cond_lst');

   lv_state = getappdata(gcf,'CurrLVState');
   lv_idx = find(lv_state == 1);
   num_conds = num_cond_lst(1);

   min_x = 0.5;				max_x = size(designlv,1)+0.5;
   min_y = min(designlv(:));		max_y = max(designlv(:));
   margin_x = abs((max_x - min_x) / 20);
   margin_y = abs((max_y - min_y) / 20);

%   grp_range = sum(num_in_grp(1:grp_idx))+1:sum(num_in_grp(1:(grp_idx+1)));

if(1)
   ax_hdl = getappdata(gcf,'bottom_axes');
   axes(ax_hdl);
   set(ax_hdl,'visible','off');
end

   %  plot of the designlv
   %
   ax_hdl = getappdata(gcf,'top_axes');
   axes(ax_hdl);
   cla;hold on;

   %  the rows are stacked by groups. each group has several conditions.
   %  each condition could have several contrasts.
   %
%   num_rows = size(designlv,1);
%   num_rows = num_conds;

%   tick_step = round(num_rows / 20);

   load('rri_color_code');

   num_grp = getappdata(gcf,'num_grp');

   for g = 1:num_grp
   for k = 1:num_conds
      bar_hdl = bar((g-1)*num_conds + k, designlv((g-1)*num_conds + k,lv_idx));
      set(bar_hdl,'facecolor',color_code(k,:));
   end
   end

   hold off;

   axis([min_x,max_x,min_y-margin_y,max_y+margin_y]);

   set(ax_hdl, 'userdata', 'topPlotDesignLV');
   % set(ax_hdl,'xtick',[1:tick_step:num_rows]);
%   set(ax_hdl,'tickdir','out','ticklength', [0.005 0.005], ...
%	'box','on','xtick',[]);
   set(ax_hdl,'tickdir','out','ticklength', [0.005 0.005], ...
	'box','on');

%   min_value = min(designlv(:,lv_idx));
%   max_value = max(designlv(:,lv_idx));
%   offset = (max_value - min_value) / 20;
%   axis([0 size(designlv,1)+1 min_value-offset max_value+offset]);

   ylabel('Weights');

   if(getappdata(gcf, 'is_design_plot'))
      title('Weights of the contrasts for the Design LV');
   else
      title('Weights of the contrasts for the Behavior LV');
   end

   grid on;

   set(ax_hdl,'xtick',([1:num_grp] - 1)*num_conds + 0.5);
   set(ax_hdl,'xticklabel',1:num_grp);

   conditions = getappdata(gcf, 'conditions');

   if ~isempty(conditions),

      % remove the old legend to avoid the bug in the MATLAB5
      old_legend = getappdata(gcf,'LegendHdl3');
      if ~isempty(old_legend),
        try
          delete(old_legend{1});
        catch
        end;
      end;

      % create a new legend, and save the handles
      [l_hdl, o_hdl] = legend(conditions, 0);
      legend_txt(o_hdl);
      set(l_hdl,'color',[0.9 1 0.9]);
      setappdata(gcf,'LegendHdl3',[{l_hdl} {o_hdl}]);

      legend_state = get(findobj(gcf,'Tag','LegendMenu'),'Userdata');
      if (legend_state == 1),
	 DisplayLegend('on');
      else
	 DisplayLegend('off');
      end;

   else

      setappdata(gcf,'LegendHdl3',[]);

   end;

   xlabel('Groups');

if(0)

   %  plot of the designlv permuation result if any
   %
   ax_hdl = getappdata(gcf,'bottom_axes');
   axes(ax_hdl);
   cla; grid off;


%cla;
%xlabel('');
%ylabel('');
%title('');
set(ax_hdl,'visible','off');
return;


   if isempty(perm_result)
      title('--- No permutation test has been performed --- ');
      return;
   end;

   bar(perm_result.dprob(:,lv_idx)*100,'r');
   set(ax_hdl, 'userdata', 'bottomPlotDesignLV');
   % set(ax_hdl,'XTick',[1:tick_step:num_contrasts]);
   set(ax_hdl,'xtick',[]);
   axis([0 size(designlv,1)+1 0 105]);

   xlabel('Contrasts');
   ylabel('Probability (%)');

   if(getappdata(gcf, 'is_design_plot'))
      title(sprintf('Permuted design LV greater than observed, %d permutation tests, %d%% crossblock', perm_result.num_perm, cb(lv_idx)));
   else
      title(sprintf('Permuted behav LV greater than observed, %d permutation tests, %d%% crossblock', perm_result.num_perm, cb(lv_idx)));
   end
end

   try
      txtbox_hdl = getappdata(gcf,'txtbox_hdl');
      delete(txtbox_hdl);                           % clear rri_txtbox
   catch
   end

   return;                                              % PlotDesignLV


%---------------------------------------------------------------------------

function ToggleLegend

   h = findobj(gcf,'Tag','LegendMenu');

   legend_state = get(h,'Userdata');
   switch (legend_state)
     case {0},
	set(h,'Userdata',1,'Label','&Hide Legend');
        DisplayLegend('on');
     case {1},
	set(h,'Userdata',0,'Label','&Show Legend');
        DisplayLegend('off');
   end;

   return;                                              % ToggleLegend


%---------------------------------------------------------------------------

function DisplayLegend(on_off)

   l_hdls = getappdata(gcf,'LegendHdl');
   l_hdls2 = getappdata(gcf,'LegendHdl2');
   l_hdls3 = getappdata(gcf,'LegendHdl3');

⌨️ 快捷键说明

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