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

📄 erp_plot_canonical_corr.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 3 页
字号:
   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 SetTopLVButton(top_lv_button)

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

   slider_value = total_rows - top_lv_button + 1;
   set(slider_hdl,'Value',slider_value);

   setappdata(gcf,'TopLVButton',top_lv_button);

   DisplayLVButtons;

   return;                                              % SetTopLVButton


%----------------------------------------------------------------------------
function SetupSlider()


   top_lv_button = getappdata(gcf,'TopLVButton');
   rows = getappdata(gcf,'NumLVRows');

   curr_lv_state = getappdata(gcf,'CurrLVState');
   num_lvs = length(curr_lv_state);

   total_rows = num_lvs;
   slider_hdl = findobj(gcf,'Tag','LVButtonSlider');

   if (total_rows > 1)           % don't need to update when no condition
      set(slider_hdl,'Min',1,'Max',total_rows, ...
                  'Value',total_rows-top_lv_button+1, ...
                  'Sliderstep',[1/(total_rows-1)-0.00001 1/(total_rows-1)]);
   end;

   return;                                              % UpdateSlider


%---------------------------------------------------------------------------
function SelectLV(selected_lv)

   lv_state = getappdata(gcf,'CurrLVState');
   LV_hlist = getappdata(gcf,'LV_hlist');
   top_lv = getappdata(gcf,'TopLVButton');
   rows = getappdata(gcf,'NumLVRows');
   bottom_lv = top_lv + rows - 1;


   %  remove the previous selection
   %
   prev_selected_lv = find(lv_state == 1);
   if (prev_selected_lv >= top_lv & prev_selected_lv <= bottom_lv),
      row_idx = prev_selected_lv - top_lv + 1;
      set(LV_hlist(row_idx),'Value',0);
   end;

   UpdateLVButtonList = 0;
   if ~exist('selected_lv','var')	 % select LV interactively
      curr_row = get(gcbo,'Userdata');
      curr_lv = top_lv + curr_row -1;
      set(LV_hlist(curr_row),'Value',1);
   else					 % select LV by specifying the index
      curr_lv = selected_lv;
      if (selected_lv >= top_lv & selected_lv <= bottom_lv),
         row_idx = selected_lv - top_lv + 1;
         set(LV_hlist(row_idx),'Value',1);
      else
         UpdateLVButtonList = 1;
      end;
   end;

   lv_state = zeros(1,length(lv_state));
   lv_state(curr_lv) = 1;

   setappdata(gcf,'CurrLVState',lv_state);

   if (UpdateLVButtonList)
      SetTopLVButton(curr_lv);
   end;

   return;                                              % SelectLV


%--------------------------------------------------------------------------
%
function h = delete_fig()

  try
     load('pls_profile');
     pls_profile = which('pls_profile.mat');

     erp_plot_canonical_corr_pos = get(gcbf,'position');

     save(pls_profile, '-append', 'erp_plot_canonical_corr_pos');
  catch
  end

  main_fig = getappdata(gcbf,'main_fig');
  hm_canonicalcorr = getappdata(main_fig,'hm_canonicalcorr');
  set(hm_canonicalcorr, 'userdata',0, 'check','off');

  return; 					% delete_fig


%--------------------------------------------------------------------------
function set_combine_plot()

  curr_state = get(gcbo,'Userdata');
  if (curr_state == 1),		% currently combining plots
     new_state = 0;
     set(gcbo,'Label','Combine plots within conditions');
  else
     new_state = 1;
     set(gcbo,'Label','Separate plots within conditions');
  end;

  set(gcbo,'Userdata',new_state);
  erp_plot_cond_stim_ui('COMBINE_PLOTS',new_state);

  return; 					% set_combine_plot

%--------------------------------------------------------------------------
function make_datamat_popup(data_option)
%  data_option = 1  - plot group data
%  data_option = 2  - plot all data

   popup_h = findobj(gcf,'Tag','STDatamatPopup');
   curr_option = get(popup_h,'Userdata');
   if ~isempty(curr_option) & (curr_option == data_option)
      return;				% no change, do nothing
   end;

   st_filenames = getappdata(gcf,'STFiles');

   switch (data_option)

     case {1}					% plot individual data
        num_st_datamat = length(st_filenames);
        popup_list = cell(1,num_st_datamat);
        for i=1:num_st_datamat,
           %  get rid of ".mat" extension if there is any 
           if strcmp(st_filenames{i}.name(end-3:end),'.mat')==1
              popup_list{i} = sprintf('[%d] %s', ...
                        st_filenames{i}.group, st_filenames{i}.name(1:end-4));
           else
              popup_list{i} = sprintf('[%d] %s', ...
                        st_filenames{i}.group, st_filenames{i}.name);
           end;
        end;
        alignment = 'left';

     case {2}					% plot all data
        popup_list{1} = '< All Data >';
        alignment = 'center';
   end;

   set(popup_h,'String',popup_list,'Userdata',data_option, ...
               'HorizontalAlignment', alignment,'Value',1);

   msg = 'Press "Plot" Button or select datamat to see the response function';
   set(findobj(gcf,'Tag','MessageLine'),'String',msg);

   return; 					% make_datamat_popup


%--------------------------------------------------------------------------
function condition_update(sessionFileList,with_path)
%
   h = findobj(gcf,'Tag', 'CondSlider');
   rows = get(h,'UserData');
   max_page = get(h,'Max');
   slider_value = round(get(h,'Value'));
   page = max_page - slider_value +1;
   set(h,'Value',slider_value);

   chk_box_hlist = get(findobj(gcf,'Tag','ConditionLabel'),'UserData');
   num_cond = length(chk_box_hlist);

   visible_list = zeros(1,num_cond);
   visible_list((page-1)*rows+1:page*rows) = 1;

   for i=1:num_cond,
      if(visible_list(i) == 0)
          set(chk_box_hlist(i),'Visible','off');
      else
          set(chk_box_hlist(i),'Visible','on');
      end;
   end;
   
   return;
%


%--------------------------------------------------------------------------
function get_st_datamat_filename(plsResultFile)

  warning off;
  load(plsResultFile,'datamat_files', 'num_subj_lst', 'behavdata_lst');
  warning on;

  rri_changepath('erpresult');

  if ~exist('behavdata_lst','var')
     for i=1:length(datamat_files)
        load(datamat_files{i});
        behavdata_lst{i} = session_info.behavdata;
     end
  end

  rri_changepath('erpresult');

  cnt = 0;
  num_groups = length(datamat_files);

  for i=1:num_groups,
        cnt = cnt + 1;

        [tmp fname]=rri_fileparts(datamat_files{i});
        st_filename{cnt}.name = fname;
        st_filename{cnt}.fullname = datamat_files{i};
        st_filename{cnt}.group = i;
	st_filename{cnt}.behavdata = behavdata_lst{i};
  end;

  setappdata(gcf,'STFiles',st_filename);
  setappdata(gcf,'num_subj_lst',num_subj_lst);
  setappdata(gcf,'behavdata_lst',behavdata_lst);

  return;                                       % get_st_datamat_filename


%--------------------------------------------------------------------------
%
function  [behavdata,st_datamat,st_win_size,st_evt_list] = ...
					load_plotted_datamat(selected_idx)

   old_pointer = get(gcf,'Pointer');
   set(gcf,'Pointer','watch');

   st_filename = getappdata(gcf,'STFiles');

   h = findobj(gcf,'Tag','STDatamatPopup');
   selected_idx = get(h,'Value');
   data_option = get(h,'Userdata');

   switch (data_option)
      case {1}, 
         selected_files{1} = st_filename{selected_idx}.fullname;
      case {2},
         cnt = 0;
         for i=1:length(st_filename),
            selected_files{i} = st_filename{i}.fullname;
         end;
   end; 

   %  merge files together
   [st_datamat, st_win_size, num_voxels, st_evt_list] = ...
				merge_st_datamat(selected_files);

   nr = length(st_evt_list);
   nc = num_voxels;
   st_datamat = reshape(st_datamat,[nr,st_win_size,nc]);

   set(gcf,'Pointer',old_pointer);

%   plsResultFile = getappdata(gcf,'plsResultFile');
%   load(plsResultFile,'behavdata_lst');
   behavdata_lst = getappdata(gcf,'behavdata_lst');
   behavdata = behavdata_lst{selected_idx};

   return;                                       % load_plotted_datamat


%--------------------------------------------------------------------------
%
function  [grp_st_datamat, win_size, num_voxels, evt_list] = ...
				merge_st_datamat(selected_files)

   num_files = length(selected_files);
   cond_selection = getappdata(gcf,'cond_selection');
   chan_selection = getappdata(gcf,'chan_selection');
   common_time_info = getappdata(gcf,'common_time_info');

   win_size = common_time_info.timepoint;
   num_voxels = sum(chan_selection);
   num_cols = win_size * num_voxels;
%   grp_st_datamat = zeros(total_num_evt,num_cols);
   evt_list = [];
   first_row = 1;

   %  compute the common coords first and the total number of events
   %
   for i=1:num_files,

      load(selected_files{i});
      rri_changepath('erpdatamat');
      rri_changepath('erpdata');

      load(datafile);

      tmp_datamat = erp_datacub2datamat(datamat, common_time_info, ...
		session_info, chan_selection, selected_subjects, cond_selection);

      st_evt_list = [];

      for j=1:sum(cond_selection)
         st_evt_list = [st_evt_list j*ones(1,sum(selected_subjects))];
      end

      last_row = length(st_evt_list) + first_row - 1;

      grp_st_datamat(first_row:last_row,:) = tmp_datamat;
      evt_list = [evt_list st_evt_list];

      first_row = last_row + 1;

      clear tmp_datamat;
   end; 

   return;                               	% merge_st_datamat


%---------------------------------------------------------------------------
function [brainlv,conditions,cond_selection,chan_selection, ...
	common_time_info,bscan] = load_pls_brainlv(fname)

   brainlv = [];
   conditions = [];
   cond_selection = [];
   chan_selection = [];
   common_time_info = [];

   % the following part will not get called during plsgui
   %
   if ~exist('fname','var') | isempty(fname),
     f_pattern = '*ERPresult.mat';
     [PLSresultFile,PLSresultFilePath] = uigetfile(f_pattern,'Load PLS scores');

     if isequal(PLSresultFile,0), 
        return;
     end;

     fname = [PLSresultFilePath,PLSresultFile];
   end;

   try 
      warning off;
      load( fname,'salience','cond_name','common_conditions','common_channels','common_time_info','bscan');
      warning on;
   catch
      msg = sprintf('Cannot load the PLS result from file: %s',PLSresultFile);
      disp(['ERROR: ' msg]);
      return;
   end;

   brainlv = salience;
   conditions = cond_name(find(common_conditions));
   cond_selection = common_conditions;
   chan_selection = common_channels;

   if ~exist('bscan','var') | isempty(bscan)
      bscan = 1:sum(cond_selection);
   end

   return;					% load_pls_brainlv 


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

⌨️ 快捷键说明

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