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

📄 pet_analysis_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 5 页
字号:
   slider_hdl = findobj(gcf,'Tag','GroupSlider');
   set(slider_hdl,'visible','on'); 

   return;						% ShowSlider


%----------------------------------------------------------------------------
function HideSlider()

   slider_hdl = findobj(gcf,'Tag','GroupSlider');
   set(slider_hdl,'visible','off');

   return;						% HideSlider


%----------------------------------------------------------------------------
function SelectTaskPLS;

   if get(findobj(gcf,'Tag','TaskPLSBn'),'Value') == 0		% click itself
      set(findobj(gcf,'Tag','TaskPLSBn'),'Value',1);
   else
      set(findobj(gcf,'Tag','SelectContrastData'),'Value',0);
      set(findobj(gcf,'Tag','BehavPLSBn'),'Value',0);
      set(findobj(gcf,'Tag','SelectMultiblockData'),'Value',0);

      set(findobj(gcf,'Tag','ContrastFileEdit'),'BackGroundColor',[0.9 0.9 0.9]);
      set(findobj(gcf,'Tag','ContrastDataLabel'),'Enable','off');
      set(findobj(gcf,'Tag','ContrastFileEdit'),'Enable','off');
      set(findobj(gcf,'Tag','ContrastFileButton'),'Enable','off');

      set(findobj(gcf,'Tag','PosthocDataEdit'),'BackGroundColor',[0.9 0.9 0.9]);
      set(findobj(gcf,'Tag','ModifyBehavdataMenu'),'Enable','off');
      set(findobj(gcf,'Tag','PosthocDataLabel'),'Enable','off');
      set(findobj(gcf,'Tag','PosthocDataEdit'),'Enable','off');
      set(findobj(gcf,'Tag','PosthocDataBn'),'Enable','off');

      set(findobj(gcf,'Tag','ClimEdit'),'BackGroundColor',[0.9 0.9 0.9]);
      set(findobj(gcf,'Tag','ClimLabel'),'Enable','off');
      set(findobj(gcf,'Tag','ClimEdit'),'Enable','off');

      set(findobj(gcf,'Tag','MultiblockDeselectConditionMenu'),'Enable','off');
   end

   return;						% SelectTaskPLS


%----------------------------------------------------------------------------
function SelectContrastData;

   if get(findobj(gcf,'Tag','SelectContrastData'),'Value') == 0	% click itself
      set(findobj(gcf,'Tag','SelectContrastData'),'Value',1);
   else
      set(findobj(gcf,'Tag','TaskPLSBn'),'Value',0);
      set(findobj(gcf,'Tag','BehavPLSBn'),'Value',0);
      set(findobj(gcf,'Tag','SelectMultiblockData'),'Value',0);

      set(findobj(gcf,'Tag','PosthocDataEdit'),'BackGroundColor',[0.9 0.9 0.9]);
      set(findobj(gcf,'Tag','ModifyBehavdataMenu'),'Enable','off');
      set(findobj(gcf,'Tag','PosthocDataLabel'),'Enable','off');
      set(findobj(gcf,'Tag','PosthocDataEdit'),'Enable','off');
      set(findobj(gcf,'Tag','PosthocDataBn'),'Enable','off');

      set(findobj(gcf,'Tag','ContrastFileEdit'),'BackGroundColor',[1 1 1]);
      set(findobj(gcf,'Tag','ContrastDataLabel'),'Enable','on');
      set(findobj(gcf,'Tag','ContrastFileEdit'),'Enable','on');
      set(findobj(gcf,'Tag','ContrastFileButton'),'Enable','on');

      set(findobj(gcf,'Tag','ClimEdit'),'BackGroundColor',[0.9 0.9 0.9]);
      set(findobj(gcf,'Tag','ClimLabel'),'Enable','off');
      set(findobj(gcf,'Tag','ClimEdit'),'Enable','off');

      set(findobj(gcf,'Tag','MultiblockDeselectConditionMenu'),'Enable','off');
   end

   return;						% SelectContrastData


%----------------------------------------------------------------------------
function SelectBehavPLS

   if get(findobj(gcf,'Tag','BehavPLSBn'),'Value') == 0		% click itself
      set(findobj(gcf,'Tag','BehavPLSBn'),'Value',1);
   else
      set(findobj(gcf,'Tag','TaskPLSBn'),'Value',0);
      set(findobj(gcf,'Tag','SelectMultiblockData'),'Value',0);
      set(findobj(gcf,'Tag','SelectContrastData'),'Value',0);

      set(findobj(gcf,'Tag','ContrastFileEdit'),'BackGroundColor',[0.9 0.9 0.9]);
      set(findobj(gcf,'Tag','ContrastDataLabel'),'Enable','off');
      set(findobj(gcf,'Tag','ContrastFileEdit'),'Enable','off');
      set(findobj(gcf,'Tag','ContrastFileButton'),'Enable','off');

      set(findobj(gcf,'Tag','PosthocDataEdit'),'BackGroundColor',[1 1 1]);
      set(findobj(gcf,'Tag','ModifyBehavdataMenu'),'Enable','on');
      set(findobj(gcf,'Tag','PosthocDataLabel'),'Enable','on');
      set(findobj(gcf,'Tag','PosthocDataEdit'),'Enable','on');
      set(findobj(gcf,'Tag','PosthocDataBn'),'Enable','on');

      num_boot = str2num(get(findobj(gcf,'Tag','NumBootstrapEdit'),'String'));
      if  ~isempty(num_boot) & num_boot ~= 0
         set(findobj(gcf,'Tag','ClimEdit'),'BackGroundColor',[1 1 1]);
         set(findobj(gcf,'Tag','ClimLabel'),'Enable','on');
         set(findobj(gcf,'Tag','ClimEdit'),'Enable','on');
      end

      set(findobj(gcf,'Tag','MultiblockDeselectConditionMenu'),'Enable','off');
   end

   return;						% SelectBehavPLS


%----------------------------------------------------------------------------
function SelectMultiblockData;

   if get(findobj(gcf,'Tag','SelectMultiblockData'),'Value') == 0	% click itself
      set(findobj(gcf,'Tag','SelectMultiblockData'),'Value',1);
   else
      set(findobj(gcf,'Tag','TaskPLSBn'),'Value',0);
      set(findobj(gcf,'Tag','BehavPLSBn'),'Value',0);
      set(findobj(gcf,'Tag','SelectContrastData'),'Value',0);

      set(findobj(gcf,'Tag','ContrastFileEdit'),'BackGroundColor',[0.9 0.9 0.9]);
      set(findobj(gcf,'Tag','ContrastDataLabel'),'Enable','off');
      set(findobj(gcf,'Tag','ContrastFileEdit'),'Enable','off');
      set(findobj(gcf,'Tag','ContrastFileButton'),'Enable','off');

      set(findobj(gcf,'Tag','PosthocDataEdit'),'BackGroundColor',[1 1 1]);
      set(findobj(gcf,'Tag','ModifyBehavdataMenu'),'Enable','on');
      set(findobj(gcf,'Tag','PosthocDataLabel'),'Enable','on');
      set(findobj(gcf,'Tag','PosthocDataEdit'),'Enable','on');
      set(findobj(gcf,'Tag','PosthocDataBn'),'Enable','on');

      num_boot = str2num(get(findobj(gcf,'Tag','NumBootstrapEdit'),'String'));
      if  ~isempty(num_boot) & num_boot ~= 0
         set(findobj(gcf,'Tag','ClimEdit'),'BackGroundColor',[1 1 1]);
         set(findobj(gcf,'Tag','ClimLabel'),'Enable','on');
         set(findobj(gcf,'Tag','ClimEdit'),'Enable','on');
      end

      set(findobj(gcf,'Tag','MultiblockDeselectConditionMenu'),'Enable','on');
   end

   return;						% SelectMultiblockData


%----------------------------------------------------------------------------
function EditNumBoot

   %  contain behavpls
   %
   if get(findobj(gcf,'Tag','BehavPLSBn'),'Value') == 1 | ...
	get(findobj(gcf,'Tag','SelectMultiblockData'),'Value') == 1

      num_boot = str2num(get(findobj(gcf,'Tag','NumBootstrapEdit'),'String'));
      if  ~isempty(num_boot) & num_boot ~= 0
         set(findobj(gcf,'Tag','ClimEdit'),'BackGroundColor',[1 1 1]);
         set(findobj(gcf,'Tag','ClimLabel'),'Enable','on');
         set(findobj(gcf,'Tag','ClimEdit'),'Enable','on');
      else
         set(findobj(gcf,'Tag','ClimEdit'),'BackGroundColor',[0.9 0.9 0.9]);
         set(findobj(gcf,'Tag','ClimLabel'),'Enable','off');
         set(findobj(gcf,'Tag','ClimEdit'),'Enable','off');
      end
   end

   return;						% EditNumBoot


%----------------------------------------------------------------------------
function SelectContrastNone;

   if get(findobj(gcf,'Tag','ContrastNoneChkBox'),'Value') == 0		% click itself
      set(findobj(gcf,'Tag','ContrastNoneChkBox'),'Value',1);
   else
      set(findobj(gcf,'Tag','ContrastHelmertChkBox'),'Value',0);

      set(findobj(gcf,'Tag','ContrastFileChkBox'),'Value',0);
      set(findobj(gcf,'Tag','ContrastFileEdit'),'Enable','off');
      set(findobj(gcf,'Tag','ContrastFileButton'),'Enable','off');
   end

   return;						% SelectContrastNone


%----------------------------------------------------------------------------
function SelectContrastHelmert

   if get(findobj(gcf,'Tag','ContrastHelmertChkBox'),'Value') == 0
      set(findobj(gcf,'Tag','ContrastHelmertChkBox'),'Value',1);
   else
      set(findobj(gcf,'Tag','ContrastNoneChkBox'),'Value',0);

      set(findobj(gcf,'Tag','ContrastFileChkBox'),'Value',0);
      set(findobj(gcf,'Tag','ContrastFileEdit'),'Enable','off');
      set(findobj(gcf,'Tag','ContrastFileButton'),'Enable','off');
   end

   return;						% SelectContrastHelmert


%----------------------------------------------------------------------------
function SelectContrastFile

   if get(findobj(gcf,'Tag','ContrastFileChkBox'),'Value') == 0
      set(findobj(gcf,'Tag','ContrastFileChkBox'),'Value',1);
   else
      set(findobj(gcf,'Tag','ContrastNoneChkBox'),'Value',0);
      set(findobj(gcf,'Tag','ContrastHelmertChkBox'),'Value',0);

      set(findobj(gcf,'Tag','ContrastFileEdit'),'Enable','on');
      set(findobj(gcf,'Tag','ContrastFileButton'),'Enable','on');
   end

   return;						% SelectContrastFile

%----------------------------------------------------------------------------
function status = SavePLSOptions

   status = -1;
   setappdata(gcf,'PLSoptions',[]);

   %  profiles
   %
   curr_profiles = getappdata(gcf,'CurrGroupProfiles');
   num_groups = length(curr_profiles);

   if num_groups == 0
      msg = 'ERROR: Datamat group is not specified.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   end

   save_datamat = get(findobj(gcf,'Tag','SaveDatamatChkbox'),'Value');
   isbehav = get(findobj(gcf,'Tag','BehavPLSBn'),'Value');
   iscontrast = get(findobj(gcf,'Tag','SelectContrastData'),'Value');
   ismultiblock = get(findobj(gcf,'Tag','SelectMultiblockData'),'Value');

   PLSoptions.save_datamat = save_datamat;
   PLSoptions.cond_selection = getappdata(gcf,'cond_selection');
   PLSoptions.behavname = getappdata(gcf,'behavname');
   PLSoptions.behavdata = getappdata(gcf,'behavdata');
   PLSoptions.behavdata_lst = getappdata(gcf,'behavdata_lst');
   PLSoptions.bscan = getappdata(gcf,'bscan');
   if isempty(PLSoptions.bscan)
      PLSoptions.bscan = 1:sum(PLSoptions.cond_selection);
   end

   %  Check data integrity for behav PLS analysis
   %
   PLSoptions.profiles = cell(1,num_groups);

   for i=1:num_groups
      PLSoptions.profiles{i} = curr_profiles{i};

      behavname = {};

      warning off;
      try
         load(curr_profiles{i},'behavname');
      catch
      end
      warning on;

%      if isbehav & isempty(behavname) & isempty(PLSoptions.behavdata)
%         msg = ['ERROR: Behav data is required for BehavPLS'];
%%		curr_profiles{i}, '.'];
%         set(findobj(gcf,'Tag','MessageLine'),'String',msg);
%         return;
%      end
   end

   % make sure the conditions in each profile are the same
   %
   total_profiles = ValidateProfiles(PLSoptions.profiles);

   if (total_profiles == -1)
      return;
   end;

   PLSoptions.TotalNumberProfiles = total_profiles;

   if (ismultiblock == 1)

      PLSoptions.ismultiblock = 1;
      PLSoptions.ismean = 1;
      PLSoptions.isbehav = 1;
      PLSoptions.iscontrast = 0;
      PLSoptions.ContrastFile = [];

      %  posthoc data file
      %
      posthoc_data_file = getappdata(gcf, 'posthoc_data_file');
      if ~isempty(posthoc_data_file)
         try
            PLSoptions.posthoc = load(posthoc_data_file);
         catch
            msg = sprintf('Invalid posthoc data file.');
            set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
            return;
         end
         [r_posthoc,c_posthoc] = size(PLSoptions.posthoc);
         if r_posthoc ~= getappdata(gcf,'num_selected_behav') * getappdata(gcf,'num_selected_cond') * num_groups
            msg = sprintf('Rows in Posthoc data file do not match.');
            set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
            return;
         end
      else
         PLSoptions.posthoc = [];
      end

   elseif (isbehav == 1)

      PLSoptions.ismultiblock = 0;
      PLSoptions.ismean = 0;
      PLSoptions.isbehav = 1;
      PLSoptions.iscontrast = 0;
      PLSoptions.ContrastFile = [];

      %  posthoc data file
      %
      posthoc_data_file = getappdata(gcf, 'posthoc_data_file');
      if ~isempty(posthoc_data_file)
         try
            PLSoptions.posthoc = load(posthoc_data_file);
         catch
            msg = sprintf('Invalid posthoc data file.');
            set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
            return;
         end
         [r_posthoc,c_posthoc] = size(PLSoptions.posthoc);
         if r_posthoc ~= getappdata(gcf,'num_selected_behav') * getappdata(gcf,'num_selected_cond') * num_groups
            msg = sprintf('Rows in Posthoc data file do not match.');
            set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
            return;
         end
      else
         PLSoptions.posthoc = [];
      end

   elseif (iscontrast == 1)			% contrast

      PLSoptions.ismultiblock = 0;
      PLSoptions.ismean = 0;
      PLSoptions.isbehav = 0;
      PLSoptions.iscontrast = 1;
      PLSoptions.posthoc = [];
      PLSoptions.ContrastFile = get(findobj(gcf,'tag','ContrastFileEdit'),'string');

      if isempty(PLSoptions.ContrastFile),
          msg = 'ERROR: Contrast file is not specified.';
          set(findobj(gcf,'Tag','MessageLine'),'String',msg);
          return;
      end;

      try
          use_contrast = load(PLSoptions.ContrastFile,'conditions');
          cond_selection = getappdata(gcf,'cond_selection');

          if size(use_contrast,1) ~= sum(cond_selection)*num_groups
             msg = 'ERROR: incompetible number of condition in contrast.';
             set(findobj(gcf,'Tag','MessageLine'),'String',msg);
             return;
          end
      catch
          msg = 'ERROR: cannot load the contrast file.';
          set(findobj(gcf,'Tag','MessageLine'),'String',msg);
          return;
      end;

      %  check if the contrast matrix is rank deficient
      %
      if (rank(use_contrast) ~= size(use_contrast,2))
         msg = 'Your Contrast matrix is rank deficient. Please check your contrasts and run the program again';
         uiwait(msgbox(msg,'Warning: Contrasts are not linear independent','modal'));
%         set(findobj(gcf,'Tag','MessageLine'),'String',msg);
%         return;	
      end;

      %  check if the contrast matrix is orthogonal
      %
%      if abs(sum(sum(use_contrast'*use_contrast-diag(diag(use_contrast'*use_contrast))))) > 1e-6
      check_orth = abs(triu(use_contrast'*use_contrast) - tril(use_contrast'*use_contrast));
      if max(check_orth(:)) > 1e-6
         msg = 'Effects expressed by each contrast are not independent. Check variable lvintercorrs in result file to see overlap of effects between LVs';
         uiwait(msgbox(msg,'Warning: Contrasts are not orthogonal','modal'));
%         set(findobj(gcf,'Tag','MessageLine'),'String',msg);
%         return;	
      end

   else						% deviation

      PLSoptions.ismultiblock = 0;
      PLSoptions.ismean = 1;
      PLSoptions.isbehav = 0;
      PLSoptions.iscontrast = 0;
      PLSoptions.posthoc = [];
      PLSoptions.ContrastFile = [];

   end

   %  number of permutation
   %
   h = findobj(gcf,'Tag','NumPermutationEdit');
   PLSoptions.num_perm = str2num(get(h,'String'));
   if isempty(PLSoptions.num_perm)
      msg = 'ERROR: Invalid number of permutation specified.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   end;

   %  number of bootstrap
   %
   h = findobj(gcf,'Tag','NumBootstrapEdit');
   PLSoptions.num_boot = str2num(get(h,'String'));
   if isempty(PLSoptions.num_boot)
      msg = 'ERROR: Invalid number of bootstrap specified.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   end;

   %  upper limit of confidence interval estimated
   %
   h = findobj(gcf,'Tag','ClimEdit');
   PLSoptions.Clim = str2num(get(h,'String'));
   if isempty(PLSoptions.Clim)
      msg = 'ERROR: Invalid upper limit of confidence specified.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   end;

%   if (PLSoptions.num_boot > 0)
%      min_subj_required = 3;
%         for i=1:num_groups,
%           if (length(PLSoptions.profiles{i}) < min_subj_required)
%              msg = 'All groups must have at least 3 subjects for bootstrap.';
%              set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ' msg]);
%              return;

⌨️ 快捷键说明

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