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

📄 pet_plot_brain_scores.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 3 页
字号:
%PET_PLOT_BRAIN_SCORES Plot Brain Scores versus Behavior Data
%
%  USAGE: brainscore_fig = pet_plot_brain_scores('STARTUP', resultfile)
%
%--------------------------------------------------------------------

function fig = pet_plot_brain_scores(action,varargin)
%
%  pet_plot_brain_scores(action,action_arg1,...)

   if ~exist('action','var') | isempty(action) 		% no action argument
      return;
   end;

   fig = [];

   if strcmp(action,'STARTUP')			    

      plsResultFile = varargin{1};

      [tmp tit_fn] = rri_fileparts(get(gcf,'name'));
      fig = init(plsResultFile, tit_fn);

      SetupLVButtonRows;
      SetupSlider;
      DisplayLVButtons;

      return;

   end

   %  clear the message line,
   %
   h = findobj(gcf,'Tag','MessageLine');
   set(h,'String','');

   switch (upper(action))
     case {'LOAD_STDATAMAT'}
         plot_brain_scores;
     case {'MOVE_SLIDER'},
         MoveSlider;
     case {'SET_TOP_LV_BUTTON'},
         lv_idx = varargin{2};
         SetTopLVButton(lv_idx);
     case {'SELECT_LV'},
	 SelectLV;
         active_plot = getappdata(gcf,'PET_PLOT_BS_ACTIVE');
         if ~isempty(active_plot) & (active_plot == 1)
            plot_brain_scores;
         end;
     case {'DELETE_FIGURE'}
         delete_fig;
     case {'PLOT_BRAINSCORES'}
         plot_brain_scores;
     case {'MENU_PLOTINDIVIDUALDATA'}
         make_datamat_popup(1);
     case {'MENU_PLOTGROUPDATA'}
         make_datamat_popup(2);
     case {'MENU_PLOTALLDATA'}
         make_datamat_popup(3);
     case {'MENU_COMBINEPLOTS'}
         set_combine_plot;
     case {'TOGGLE_BRAIN'},
         ToggleBrain;
     case {'TOGGLE_ERROR'},
         ToggleError;
     case {'TOGGLE_DETAIL'},
         ToggleDetail;
     case {'TOGGLE_DLV'},
         ToggleDLV;
     case {'TOGGLE_ALLERR'},
         ToggleAllerr;
   end

   return;


%--------------------------------------------------------------------------
%
function fig = init(plsResultFile, tit_fn)

   tit = ['Brain scores plot for behavior analysis  [', tit_fn, ']'];
   cond_selection = getappdata(gcf,'cond_selection');

   save_setting_status = 'on';
   pet_plot_brain_scores_pos = [];

   try
      load('pls_profile');
   catch
   end

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

      pos = pet_plot_brain_scores_pos;

   else

      w = 0.8;
      h = 0.7;
      x = (1-w)/2;
      y = (1-h)/2;

      pos = [x y w h];

   end

   hh = figure('Units','normal', ...
	   'user','Brain scores plot for behavior analysis', ...
	   'name',tit, ...
	   'NumberTitle','off', ...
	   'Color', [0.8 0.8 0.8], ...
 	   'DoubleBuffer','on', ...
	   'Menubar', 'none', ...
	   'DeleteFcn', 'pet_plot_brain_scores(''Delete_Figure'');', ...
	   'Position',pos, ...
	   'Tag','PlotBrainScoreFig');


   %  display datamat
   %

   x = 0.05;
   y = 0.9;
%   w = 0.15;
   w = 0.12;
   h = 0.06;

   pos = [x y w h];

   fnt = 0.4;

   h0 = uicontrol('Parent',hh, ...
           'units','normal', ...
	   'FontUnits', 'normal', ...
	   'FontSize', fnt, ...
	   'BackgroundColor', [0.8 0.8 0.8], ...
 	   'Style', 'text', ...
	   'Position', pos, ...	
           'HorizontalAlignment', 'left',...
	   'String', 'Datamat:', ...
	   'Tag', 'STDatamatLabel');
	   
   %  create ST datamat popup menu
   %
   y = 0.84;
%   w = 0.22;

   pos = [x y w h];

   cb_fn = [ 'pet_plot_brain_scores(''Load_STDatamat'');'];
   popup_h = uicontrol('Parent',hh, ...
           'units','normal', ...
	   'FontUnits', 'normal', ...
	   'FontSize', fnt, ...
           'Style', 'popupmenu', ...
	   'Position', pos, ...
           'HorizontalAlignment', 'left',...
	   'String', '', ...
	   'Value', 1, ...
	   'Tag', 'STDatamatPopup', ...
	   'Callback',cb_fn);

   y = 0.18;
   h = 0.62;

   pos = [x y w h];

   h0 = uicontrol('Parent',hh, ...
           'Units','normal', ...
	   'BackgroundColor', [0.8 0.8 0.8], ...
 	   'Style', 'frame', ...
	   'Position', pos, ...	
           'HorizontalAlignment', 'left',...
	   'Tag', 'LVFrame');

%   x = 0.09;
   x = 0.06;
   y = 0.76;
%   w = 0.14;
   w = 0.1;
   h = 0.06;

   pos = [x y w h];

   h0 = uicontrol('Parent',hh, ...
           'Units','normal', ...
	   'FontUnits', 'normal', ...
	   'FontSize', fnt, ...
	   'BackgroundColor', [0.8 0.8 0.8], ...
 	   'Style', 'text', ...
	   'Position', pos, ...	
           'HorizontalAlignment', 'center',...
	   'String', 'Display LVs', ...
	   'Tag', 'DisplayLVLabel');

   y = 0.7;
   w = 0.08;

   pos = [x y w h];

   lv_h = uicontrol('Parent',hh, ...
           'Units','normal', ...
	   'BackgroundColor', [0.8 0.8 0.8], ...
 	   'Style', 'radiobutton', ...
	   'Position', pos, ...	
           'HorizontalAlignment', 'left',...
	   'FontSize', 10, ...
	   'String', 'LV #1', ...
	   'Visible', 'on', ...
   	   'Callback','pet_plot_brain_scores(''SELECT_LV'');', ...
	   'Tag', 'LVRadioButton');

   x = x+w+0.01;
   w = 0.02;

   pos = [x y w h];

   h0 = uicontrol('Parent',hh, ...		% LV Button Slider
     	   'Style','slider', ...
   	   'Units','normal', ...
           'Min', 0, ...
           'Max', 1, ...
	   'Visible', 'on', ...
   	   'Position',pos, ...
   	   'Callback','pet_plot_brain_scores(''MOVE_SLIDER'');', ...
   	   'Tag','LVButtonSlider');

   x = 0.05  +0.01;
   y = 0.08;
   w = 0.1;

   pos = [x y w h];

   h0 = uicontrol('Parent',hh, ...
          'Units','normal', ...
          'FontUnits', 'normal', ...
          'FontSize', fnt, ...
          'Style', 'push', ...
	  'Position', pos, ...
          'String', 'Close', ...
          'CallBack', 'close(gcf)', ...
	  'Tag', 'CloseButton');

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

   pos = [x y w h];

   h0 = uicontrol('Parent',hh, ...		% Message Line
   	'Style','text', ...
   	'Units','normal', ...
        'FontUnits', 'normal', ...
        'FontSize', fnt, ...
   	'BackgroundColor',[0.8 0.8 0.8], ...
   	'ForegroundColor',[0.8 0.0 0.0], ...
   	'HorizontalAlignment','left', ...
   	'Position',pos, ...
   	'String','', ...
   	'Tag','MessageLine');

   %  file
   %
   rri_file_menu(hh);

  %  plot
  %
  h_plot = uimenu('Parent',hh, ...
             'Label','&Plot', ...
             'Enable','on',...
             'Tag','PlotMenu');
  h0 = uimenu('Parent',h_plot, ...
             'Label','Show &Brain Scores Overview', ...
             'callback','pet_plot_brain_scores(''TOGGLE_DETAIL'');', ...
             'Tag','DetailMenu');
  h0 = uimenu('Parent',h_plot, ...
             'Label','Show &Correlation Overview', ...
             'callback','pet_plot_brain_scores(''TOGGLE_ALLERR'');', ...
             'Tag','AllerrMenu');
  h0 = uimenu('Parent',h_plot, ...
             'Label','Show Behavior &LV Overview', ...
             'callback','pet_plot_brain_scores(''TOGGLE_DLV'');', ...
             'Tag','DLVMenu');
  h0 = uimenu('Parent',h_plot, ...
	     'sepa','on', ...
             'Label','Hide Brain Scores Plot', ...
             'callback','pet_plot_brain_scores(''TOGGLE_BRAIN'');', ...
             'Tag','BrainMenu');
  h0 = uimenu('Parent',h_plot, ...
             'Label','Show Correlation Plot', ...
             'callback','pet_plot_brain_scores(''TOGGLE_ERROR'');', ...
             'Tag','ErrorMenu');

  %  option
  %
  h_option = uimenu('Parent',hh, ...
             'Label','&Option', ...
             'Tag','OptionMenu', ...
             'Enable','on',...
             'Visible','on');
  h0 = uimenu('parent',h_option, ...
	     'label','&Show Legend', ...
	     'visible','off', ...
	     'userdata',0, ...		% show legend
	     'callBack', 'pet_plot_cond_stim_ui(''TOGGLELEGEND'');', ...
	     'tag','LegendMenu');
%	     'sepa','on', ...
  h0 = uimenu('Parent',h_option, ...
	     'Label','Change plot dimension', ...
	     'Tag','ChgPlotDims', ...
	     'Callback','pet_plot_cond_stim_ui(''CHANGE_PLOT_DIMS'');');


  lv_template = copyobj(lv_h,hh);
  set(lv_template,'Tag','LVTemplate','Visible','off');
  setappdata(hh,'result_file',plsResultFile);

  % load the brain scores, conditions, evt_list
  %
  [brainscores,behavlv,s,conditions,selected_conditions, ...
	num_cond_lst,num_subj_lst,lvcorrs,boot_result,perm_result, ...
	session_info,datamat_files,cond_selection] = ...
		load_pls_brainscores(plsResultFile,cond_selection);

  setappdata(hh,'cond_selection',cond_selection);

  % construct the popup label list
  %
  get_datamat_filename(datamat_files);
  make_datamat_popup(1);


  num_lv = size(brainscores,2);
  curr_lv_state = zeros(1,num_lv); 
  curr_lv_state(1) = 1;

  setappdata(hh,'tit_fn',tit_fn);
  setappdata(hh,'s',s);
  setappdata(hh,'num_cond_lst',num_cond_lst);
  setappdata(hh,'num_subj_lst',num_subj_lst);
  setappdata(hh,'perm_result',perm_result);
  setappdata(hh,'boot_result',boot_result);
  setappdata(hh,'lvcorrs',lvcorrs);
  setappdata(hh,'brainscores',brainscores);
  setappdata(hh,'behavlv',behavlv);
  setappdata(hh,'session_info',session_info);
  setappdata(hh,'selected_conditions',selected_conditions);

  setappdata(hh,'Conditions',conditions);
  setappdata(hh,'CurrLVState',curr_lv_state);

  % for GUI
  setappdata(hh,'LVButtonHeight',0.06);
  setappdata(hh,'LV_hlist',[lv_h]);
  setappdata(hh,'LVButtonTemplate',lv_template);
  setappdata(hh,'TopLVButton',1);

  setappdata(hh,'PLS_BS_PLOTTED_DATA',[]);
  setappdata(hh,'PLS_BS_PLOTTED_CONDITON',[]);

  if (nargout >= 1),
     fig = hh;
  end;

  setappdata(gcf,'PlotBrainState',1);
  setappdata(gcf,'PlotErrorState',0);
  setappdata(gcf,'PlotDetailState',0);
  setappdata(gcf,'PlotAllerrState',0);
  setappdata(gcf,'PlotDLVState',0);

  plot_brain_scores;

  return;					% init


% --------------------------------------------------------------------
function  SetupLVButtonRows()

   lv_hdls = getappdata(gcf,'LV_hlist');
   lv_template = getappdata(gcf,'LVButtonTemplate');

   row_height = getappdata(gcf,'LVButtonHeight');
   frame_pos = get(findobj(gcf,'Tag','LVFrame'),'Position');
   first_button_pos = get(findobj(gcf,'Tag','LVRadioButton'),'Position');

   top_frame_pos = frame_pos(2) + frame_pos(4);
   margin = top_frame_pos - (first_button_pos(2) + first_button_pos(4));
   rows = floor((frame_pos(4) - margin*1.5) / row_height);

   v_pos = (top_frame_pos - margin) - [1:rows]*row_height;

   nr = size(lv_hdls,1);
   if (rows < nr)				% too many rows
      for i=rows+1:nr,
         delete(lv_hdls(i));
      end;
      lv_hdls = lv_hdls(1:rows);
   else						% add more rows
      for i=nr+1:rows,
        new_s_hdls = copyobj(lv_template,gcf);
        lv_hdls = [lv_hdls; new_s_hdls'];
      end;
   end;

   v = 'on';
   for i=1:rows,
      new_s_hdls = lv_hdls(i);
      pos = get(new_s_hdls(1),'Position'); pos(2) = v_pos(i);
      set(new_s_hdls,'String','','Position',pos,'Visible',v,'UserData',i);
   end;

   %  setup slider position
   %
   h = findobj(gcf,'Tag','LVButtonSlider');
   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



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

⌨️ 快捷键说明

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