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

📄 struct_analysis_ui.m

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

   group_h = 0.05;
   setappdata(h0,'GroupHeight', group_h);

   lower_h = 0.08;	% vert. space for Number of groups etc.
   setappdata(h0,'lower_h',lower_h);

   setappdata(h0,'CurrGroupProfiles',[]);
   setappdata(h0,'TopGroupIdx',1);
   setappdata(h0,'full_path', 0);
   setappdata(h0,'num_selected_cond',1);
   setappdata(h0,'posthoc_data_file','');

   setappdata(h0,'cond_selection',[]);
   setappdata(h0,'bscan',[]);
   setappdata(gcf,'behavname',{});
   setappdata(gcf,'behavdata',[]);
   setappdata(gcf,'behavdata_lst',{});

   SetupGroupRows;
   CreateAddRow;
   DisplayGroupProfiles(0);
   UpdateSlider;

   return;							% Init


%----------------------------------------------------------------------------
function SetupGroupRows()

   group_hdls = getappdata(gcf,'Group_hlist');
   group_h = getappdata(gcf,'GroupHeight');
   lower_h = getappdata(gcf,'lower_h');

   bottom_pos = get(findobj(gcf,'Tag','GroupProfileFrame'),'Position');
   top_pos = get(group_hdls(1,1),'Position');

   rows = floor(( top_pos(2) - bottom_pos(2) - lower_h) / group_h + 1);
   v_pos = top_pos(2) - [0:rows-1]*group_h;

   group_template = getappdata(gcf,'GroupTemplate');
   edit_cbf = '';
   select_cbf = 'struct_analysis_ui(''SELECT_GROUP'');';
   delete_cbf = 'struct_analysis_ui(''DELETE_GROUP'');';
   buttondown_group = 'struct_analysis_ui(''BUTTONDOWN_GROUP'');';

   nr = size(group_hdls,1);
   if (rows < nr)			% too many rows
      for i=rows+1:nr,
          delete(group_hdls(i,:));
      end;
      group_hdls = group_hdls(1:rows,:);
   else					% add new rows
      for i=nr+1:rows,
         new_g_hdls = copyobj(group_template,gcf);
         group_hdls = [group_hdls; new_g_hdls'];
      end;
   end;

   v = 'off';
   top_g_hdls = group_hdls(1,:);
   for i=1:rows,
      new_g_hdls = group_hdls(i,:);
      pos = get(top_g_hdls(1),'Position'); pos(2) = v_pos(i);
      set(new_g_hdls(1),'String','?','Position',pos,'Visible',v,'UserData',i);

      pos = get(top_g_hdls(2),'Position'); pos(2) = v_pos(i);
      set(new_g_hdls(2),'String','', 'Position',pos, 'Visible',v, ...
                        'UserData',i, 'Callback',edit_cbf, ...
			'ButtonDownFcn',buttondown_group);

      pos = get(top_g_hdls(3),'Position'); pos(2) = v_pos(i);
      set(new_g_hdls(3),'String','Delete','Position',pos,'Visible',v, ...
                        'UserData',i,'Callback',delete_cbf);

      pos = get(top_g_hdls(4),'Position'); pos(2) = v_pos(i);
      set(new_g_hdls(4),'String','Select','Position',pos,'Visible',v, ...
                        'UserData',i,'Callback',select_cbf);

   end;


   %  setup slider position
   %
   slider_hdl = findobj(gcf,'Tag','GroupSlider');
   s_pos = get(slider_hdl,'Position');

   s_pos(2) = v_pos(end);
   s_pos(4) = group_h * rows;
   set(slider_hdl,'Position',s_pos);


   setappdata(gcf,'Group_hlist',group_hdls);
   setappdata(gcf,'NumRows',rows);

   return;					% SetupGroupRows


%----------------------------------------------------------------------------
function DisplayGroupProfiles(full_path)

   curr_group_profiles = getappdata(gcf,'CurrGroupProfiles');
   top_group_idx = getappdata(gcf,'TopGroupIdx');
   group_hdls = getappdata(gcf,'Group_hlist');
   rows = getappdata(gcf,'NumRows');

   num_group = length(curr_group_profiles);

   last_row = 0;
   group_idx = top_group_idx;

   for i=1:rows
      g_hdls = group_hdls(i,:);
      if (group_idx <= num_group),
         set(g_hdls(1),'String',sprintf('Group #%d:',group_idx),'Visible','on');

         curr_group_name = sprintf('%s',curr_group_profiles{group_idx});
         if(full_path)
            set(g_hdls(2), 'String', curr_group_name, ...
                       'Visible','on');
         else
            [p_path, p_name, p_ext] = fileparts(curr_group_name);
            curr_group_name = [p_name p_ext];
            set(g_hdls(2), 'String', curr_group_name, ...
                       'Visible','on');
         end

         set(g_hdls(3),'String','Delete','Enable','on','Visible','on');
         set(g_hdls(4),'String','Select','Enable','on','Visible','on');

         group_idx = group_idx + 1;
         last_row = i;
      else
         set(g_hdls(1),'String','','Visible','off');
         set(g_hdls(2),'String','','Visible','off');
         set(g_hdls(3),'String','Delete','Visible','off');
         set(g_hdls(4),'String','Select','Visible','off');
      end;
   end;

   %  display or hide the add row
   %
   if (last_row < rows)
      row_idx = last_row+1;
      g_hdls = group_hdls(row_idx,:);
      pos = get(g_hdls(1),'Position');
      ShowAddRow(group_idx,pos(2),row_idx);
   else
      HideAddRow;
   end;

   %  display or hide the slider
   %
   if (top_group_idx ~= 1) | (last_row == rows)
     ShowSlider;
   else
     HideSlider;
   end;

   return;						% DisplayGroupProfiles


%----------------------------------------------------------------------------
function CreateAddRow()

   group_template = getappdata(gcf,'GroupTemplate');
   buttondown_group = 'struct_analysis_ui(''BUTTONDOWN_GROUP'');';

   a_hdls = copyobj(group_template,gcf);

   set(a_hdls(1),'String','','Foreground',[0.4 0.4 0.4],'Visible','off', ...
                 'UserData',1);

   set(a_hdls(2),'String','','Background',[0.9 0.9 0.9], 'Visible','off',...
		 'ButtonDownFcn',buttondown_group,'enable','inactive');

   set(a_hdls(3),'String','Add','Visible','off', ...
		     'Callback','struct_analysis_ui(''ADD_GROUP'');');

   set(a_hdls(4),'Visible','off','Enable','off');

   setappdata(gcf,'AddRowHdls',a_hdls);

   return;						% CreateAddRow


%----------------------------------------------------------------------------
function ShowAddRow(group_idx,v_pos,row_idx)

   a_hdls = getappdata(gcf,'AddRowHdls');
   g_hdls = getappdata(gcf,'Group_hlist');

   for j=1:length(a_hdls),
      new_pos = get(g_hdls(1,j),'Position');
      new_pos(2) = v_pos;

      set(a_hdls(j),'Position',new_pos);
      set(a_hdls(j),'Visible','on');
   end;

   set(a_hdls(1),'String',sprintf('Group #%d:',group_idx), ...
		'Visible','On','UserData',row_idx);
   set(a_hdls(2),'String','');
   set(a_hdls(4),'Visible','Off');


   return;						% ShowAddRow


%----------------------------------------------------------------------------
function HideAddRow()

   a_hdls = getappdata(gcf,'AddRowHdls');
   for j=1:length(a_hdls),
      set(a_hdls(j),'Visible','off');
   end;

   return;						% HideAddRow


%----------------------------------------------------------------------------
function DeleteGroupProfiles()

   curr_group_profiles = getappdata(gcf,'CurrGroupProfiles');
   group_hdls = getappdata(gcf,'Group_hlist');

   row_idx = get(gcbo,'UserData');
   group_id = get(group_hdls(row_idx,1),'String');
   start_idx = findstr(group_id,'#')+1;
   group_idx = str2num(group_id(start_idx:end-1));

   mask = ones(1,length(curr_group_profiles));  mask(group_idx) = 0;
   idx = find(mask == 1);
   curr_group_profiles = curr_group_profiles(idx);

   num_group = length(curr_group_profiles);
   set(findobj(gcf,'Tag','NumberGroupEdit'),'String',num2str(num_group));

   setappdata(gcf,'CurrGroupProfiles',curr_group_profiles);

   full_path = getappdata(gcf,'full_path');
   DisplayGroupProfiles(full_path);

   UpdateSlider;

   return;						% DeleteGroupProfiles


%----------------------------------------------------------------------------
function AddGroupProfiles()

   curr_group_profiles = getappdata(gcf,'CurrGroupProfiles');
   num_group = length(curr_group_profiles)+1;

   rows = getappdata(gcf,'NumRows');
   a_hdls = getappdata(gcf,'AddRowHdls');

   group_id = get(a_hdls(1),'String');
   start_idx = findstr(group_id,'#')+1;
   group_idx = str2num(group_id(start_idx:end-1));

   group_profile = get(a_hdls(2),'String');

   curr = pwd;
   if isempty(curr)
      curr = filesep;
   end

   pf_path = curr;
   pf_name = '';

   % if no pre-entry, open rri_getfiles window
   % otherwise, just read from pre-entry
   %
   if isempty(group_profile)

      if(group_idx ~= 1)
         [pf_path pf_name pf_ext] = fileparts(curr_group_profiles{group_idx-1});
      end

      pf_path = fullfile(pf_path, '*_STRUCTdatamat.mat');
      [pf_name pf_path] = uigetfile(pf_path, 'Select a session profile');

	% if there is error, uigetfile return 0 for pf_name or pf_path
	% isstr(0) return 0
        %
      if (~isstr(pf_name) | ~isstr(pf_path))
         return;
      end

      cd(pf_path);
      curr_group_profiles{num_group} = fullfile(pf_path, pf_name);

   elseif exist(group_profile) ~= 2
      msg = 'ERROR: Could not find the session profile you specified.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   else
      curr_group_profiles{num_group} = group_profile;
   end;

   if isempty(getappdata(gcf,'cond_selection'))
      tmp = load(curr_group_profiles{1});
      cond_selection = ones(1, tmp.session_info.num_conditions);
      setappdata(gcf, 'cond_selection', cond_selection);
   end

   setappdata(gcf,'behavname',{});
   setappdata(gcf,'behavdata',[]);
   setappdata(gcf,'behavdata_lst',{});

   setappdata(gcf,'CurrGroupProfiles',curr_group_profiles);
   set(findobj(gcf,'Tag','NumberGroupEdit'),'String',num2str(num_group));

   new_group_row = get(a_hdls(1),'UserData');
   if (new_group_row == rows),  	% the new group row is the last row
      top_group_idx = getappdata(gcf,'TopGroupIdx');
      setappdata(gcf,'TopGroupIdx',top_group_idx+1);
   end;

   group_hdls = getappdata(gcf,'Group_hlist');

   full_path = getappdata(gcf,'full_path');
   DisplayGroupProfiles(full_path);

   UpdateSlider;

   return;						% AddGroupProfiles


%----------------------------------------------------------------------------
function SelectGroupProfiles(group_idx)

   curr_group_profiles = getappdata(gcf,'CurrGroupProfiles');
   group_hdls = getappdata(gcf,'Group_hlist');

   row_idx = get(gcbo,'UserData');
   group_id = get(group_hdls(row_idx,1),'String');
   start_idx = findstr(group_id,'#')+1;
   group_idx = str2num(group_id(start_idx:end-1));

   curr_profile = curr_group_profiles{group_idx};
   [pf_path pf_name pf_ext] = fileparts(curr_profile);
   pf_path = fullfile(pf_path, '*_STRUCTdatamat.mat');
   [pf_name pf_path] = uigetfile(pf_path, 'Select a session profile');

   curr_group_profiles{group_idx} = fullfile(pf_path, pf_name);

	% if there is error, uigetfile return 0 for pf_name or pf_path
	% isstr(0) return 0
        %
      if (~isstr(pf_name) | ~isstr(pf_path))
         return;
      end;

   cd(pf_path);
   profiles_str = fullfile(pf_path, pf_name);

   if ~isempty(profiles_str)
      curr_group_profiles{group_idx} = profiles_str;
      setappdata(gcf,'CurrGroupProfiles',curr_group_profiles);
      set(group_hdls(row_idx,2),'String',profiles_str);

      tmp = load(curr_group_profiles{1});
      cond_selection = ones(1, tmp.session_info.num_conditions);
      setappdata(gcf, 'cond_selection', cond_selection);
      setappdata(gcf,'behavname',{});
      setappdata(gcf,'behavdata',[]);
      setappdata(gcf,'behavdata_lst',{});
   end;

   full_path = getappdata(gcf,'full_path');
   DisplayGroupProfiles(full_path);

   UpdateSlider;

   return;						% SelectGroupProfiles


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

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

   top_group_idx = total_rows - curr_value + 1;

   setappdata(gcf,'TopGroupIdx',top_group_idx);

   full_path = getappdata(gcf,'full_path');
   DisplayGroupProfiles(full_path);

   return;						% MoveSlider


%----------------------------------------------------------------------------
function UpdateSlider()

   top_group_idx = getappdata(gcf,'TopGroupIdx');
   rows = getappdata(gcf,'NumRows');

   curr_group_profiles = getappdata(gcf,'CurrGroupProfiles');
   num_groups = length(curr_group_profiles);

   total_rows = num_groups + 1;
   slider_hdl = findobj(gcf,'Tag','GroupSlider');

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

   return;                                              % UpdateSlider


%----------------------------------------------------------------------------
function ShowSlider()

   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


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

⌨️ 快捷键说明

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