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

📄 rri_input_subject_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 2 页
字号:
   for i=1:rows
      c_hdls = subj_hdls(i,:);
      if (subj_idx <= num_subj),
         set(c_hdls(1),'String',sprintf('%d.',subj_idx),'Visible','on');

         curr_subj_name = sprintf('%s',curr_subj{subj_idx});
         if(full_path)
             set(c_hdls(2), 'String', curr_subj_name, ...
                       'Visible', 'on');
         else
             [p_path, p_name, p_ext] = fileparts(curr_subj_name);
             curr_subj_name = [p_name p_ext];
             set(c_hdls(2), 'String', curr_subj_name, ...
                       'Visible', 'on');
         end

         set(c_hdls(3),'String','Delete','Visible','on');
         set(c_hdls(4),'String','Edit ...','Visible','on');
         set(c_hdls(3),'String','Delete','Enable','on');

         subj_idx = subj_idx + 1;
         last_row = i;
      else
         set(c_hdls(1),'String','','Visible','off');
         set(c_hdls(2),'String','','Visible','off');
         set(c_hdls(3),'String','Delete','Visible','off');
         set(c_hdls(4),'String','Edit ...','Visible','off');
      end;
   end;

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

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

   return;						% DisplaySubjects


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

   subj_template = getappdata(gcf,'SubjectTemplate');
   buttondown_subject = 'rri_input_subject_ui(''BUTTONDOWN_SUBJECTS'');';

   a_hdls = copyobj(subj_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_subject,'enable','inactive');

   set(a_hdls(3),'String','Add ...','Visible','off', ...
		     'Callback','rri_input_subject_ui(''ADD_SUBJECT'');');

   set(a_hdls(4),'String','Edit ...','Visible','off');

   setappdata(gcf,'AddRowHdls',a_hdls);

   return;						% CreateAddRow


%----------------------------------------------------------------------------
function ShowAddRow(subj_idx,v_pos,row_idx)
%
%	Add row with 'Add' button at 'v_pos' position
%	Also display the subject row number, with its 'UserData' updated with row_idx
%
   a_hdls = getappdata(gcf,'AddRowHdls');

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

      if j==1
         new_pos(2) = v_pos-0.01;
      else
         new_pos(2) = v_pos;
      end

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

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

   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 UpdateSubject(subj_idx)

   curr_subj = getappdata(gcf,'CurrSubjects');
   subj_hdls = getappdata(gcf,'Subj_hlist');

   row_idx = get(gcbo,'UserData');
   subj_idx = str2num(get(subj_hdls(row_idx,1),'String'));
   curr_subj{subj_idx} = get(gcbo,'String');

   setappdata(gcf,'CurrSubjects',curr_subj);

   return;						% UpdateSubject


%----------------------------------------------------------------------------
function DeleteSubject()

   subj_files = getappdata(gcf,'subj_files');

   curr_subj = getappdata(gcf,'CurrSubjects');
   subj_hdls = getappdata(gcf,'Subj_hlist');

   row_idx = get(gcbo,'UserData');
   subj_idx = str2num(get(subj_hdls(row_idx,1),'String'));

   mask = ones(1,length(curr_subj));  mask(subj_idx) = 0;
   idx = find(mask == 1);

   curr_subj = curr_subj(idx);
   subj_files = subj_files(:,idx);

   setappdata(gcf,'subj_files', subj_files);
   setappdata(gcf,'CurrSubjects',curr_subj);

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

   UpdateSlider;

   return;						% DeleteSubject


%----------------------------------------------------------------------------
function AddSubject()

   rows = getappdata(gcf,'NumRows');
   a_hdls = getappdata(gcf,'AddRowHdls');
   curr_subj = getappdata(gcf,'CurrSubjects');
   pls_data_dir = get(a_hdls(2),'String');
   subj_idx = str2num(get(a_hdls(1),'String'));

   condition = getappdata(gcf,'condition');
   selected_conditions = getappdata(gcf,'selected_conditions');
   subj_files = getappdata(gcf,'subj_files');

   if isempty(pls_data_dir)
      pls_data_dir = getappdata(gcf,'SessionPLSDir');
   end

   num_subj_init = ...
	str2num(get(findobj(gcf,'Tag','SubjectInitEdit'),'string'));
   subj_dir = [];

   filter = getappdata(gcf,'filter');

   old_dir = getappdata(gcf,'CurrSubjects');

   if ~isempty(old_dir)
      old_dir = fileparts(old_dir{1});
   else
      old_dir = pls_data_dir;
   end

   [subj_dir, subj_files_row, filter] = ...
	rri_getsubject_ui(condition, selected_conditions, old_dir, ...
		[], subj_files, num_subj_init, filter);

   setappdata(gcf,'filter',filter);

   if iscellstr(subj_dir)

      setappdata(gcf,'CurrSubjects',subj_dir);
      setappdata(gcf,'subj_files',subj_files_row);

      uiresume;
      return;

   end

   if isempty(subj_dir), return; end;		% CANCEL from rri_getsubject

   num_subj = length(curr_subj)+1;
   curr_subj{num_subj} = subj_dir;
   subj_files(:,num_subj) = subj_files_row;

   setappdata(gcf,'CurrSubjects',curr_subj);
   setappdata(gcf,'subj_files',subj_files);
   new_subj_row = get(a_hdls(1),'UserData');

   if (new_subj_row == rows),  	% the new subject row is the last row
      top_subj_idx = getappdata(gcf,'TopSubjectIdx');
      setappdata(gcf,'TopSubjectIdx',top_subj_idx+1);
   end;

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

   subj_hdls = getappdata(gcf,'Subj_hlist');
   if (new_subj_row == rows),  	% the new subject row is the last row
      set(gcf,'CurrentObject',subj_hdls(rows-1,2));
   else
      set(gcf,'CurrentObject',subj_hdls(new_subj_row,2));
   end;

   UpdateSlider;

   return;						% AddSubjects


%----------------------------------------------------------------------------
function EditSubject()

   condition = getappdata(gcf,'condition');
   selected_conditions = getappdata(gcf,'selected_conditions');
   subj_files = getappdata(gcf,'subj_files');
   full_path = getappdata(gcf,'full_path');

   curr_subj = getappdata(gcf,'CurrSubjects');
   subj_hdls = getappdata(gcf,'Subj_hlist');

   row_idx = get(gcbo,'UserData');
   subj_idx = str2num(get(subj_hdls(row_idx,1),'String'));

   pls_data_dir = curr_subj{subj_idx};
   if isempty(pls_data_dir),
      pls_data_dir = getappdata(gcf,'SessionPLSDir');
   end;

   if ~isempty(subj_files)
      subj_files_row_old = subj_files(:,subj_idx);
   else
      subj_files_row_old = [];
   end

   num_subj_init = ...
	str2num(get(findobj(gcf,'Tag','SubjectInitEdit'),'string'));

   filter = getappdata(gcf,'filter');

   [subj_dir, subj_files_row, filter] = ...
	rri_getsubject_ui(condition, selected_conditions, ...
		pls_data_dir, subj_files_row_old, subj_files, num_subj_init, filter);

   setappdata(gcf,'filter',filter);

   if iscellstr(subj_dir)

      setappdata(gcf,'CurrSubjects',subj_dir);
      setappdata(gcf,'subj_files',subj_files_row);

      uiresume;
      return;

   end

   if(~isempty(subj_dir)),
      curr_subj{subj_idx} = subj_dir;
      subj_files(:,subj_idx) = subj_files_row;

      if(full_path)
         set(subj_hdls(row_idx,2), 'String', subj_dir);
      else
         [p_path, p_name, p_ext] = fileparts(subj_dir);
         subj_dir = [p_name p_ext];
         set(subj_hdls(row_idx,2), 'String', subj_dir);
      end

      setappdata(gcf,'CurrSubjects',curr_subj);
      setappdata(gcf,'subj_files',subj_files);

   end;

   return;						% EditSubjects


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

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

   top_subj_idx = total_rows - curr_value + 1;

   setappdata(gcf,'TopSubjectIdx',top_subj_idx);

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

   return;						% MoveSlider


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

   subj_hdls = getappdata(gcf,'Subj_hlist');
   top_pos = get(subj_hdls(1,4),'Position');
   bottom_pos = get(subj_hdls(end,4),'Position');

   slider_hdl = findobj(gcf,'Tag','SubjSlider');
   pos = get(slider_hdl,'Position');

   pos(2) = bottom_pos(2);
   pos(4) = top_pos(2) + top_pos(4) - pos(2);

   set(slider_hdl,'Position', pos);

   return;						% SetupSlider


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

   top_subj_idx = getappdata(gcf,'TopSubjectIdx');
   rows = getappdata(gcf,'NumRows');

   curr_subj = getappdata(gcf,'CurrSubjects');
   num_subj = length(curr_subj);

   total_rows = num_subj+1;
   slider_hdl = findobj(gcf,'Tag','SubjSlider');

   if (num_subj ~= 0)		% don't need to update when no subject
      set(slider_hdl,'Min',1,'Max',total_rows, ...
                  'Value',total_rows-top_subj_idx+1, ...
                  'Sliderstep',[1/(total_rows-1)-0.00001 1/(total_rows-1)]); 
   end;
   
   return;						% UpdateSlider


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

   slider_hdl = findobj(gcf,'Tag','SubjSlider');
   set(slider_hdl,'visible','on'); 

   return;						% ShowSlider


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

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

   return;						% HideSlider


%----------------------------------------------------------------------------
function SwitchFullPath()

   h = findobj(gcf,'Tag','FullPathChkbox');
   full_path = get(h,'Value');

   setappdata(gcf,'full_path',full_path);
   DisplaySubjects(full_path);

   return;					% SwitchFullPath


%----------------------------------------------------------------------------
function DoneButtonPressed()

   curr_subj = getappdata(gcf,'CurrSubjects');
   num_subj = length(curr_subj);

   for i = 1:num_subj-1
      if isempty(curr_subj{i})
         msg = 'ERROR: All subjects must have directory specified.';
         set(findobj(gcf,'Tag','MessageLine'),'String',msg);
         return;
      end
      for j = i+1:num_subj
         if length(curr_subj{i}) == length(curr_subj{j}) ...
					& curr_subj{i} == curr_subj{j}
            msg = 'ERROR: No subjects should be duplicated.';
            set(findobj(gcf,'Tag','MessageLine'),'String',msg);
            return;
         end
      end
   end

   if isempty(curr_subj) | isempty(curr_subj{num_subj})
      msg = 'ERROR: All subjects must have directory specified.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   end

   uiresume;

   return;						% DoneButtonPressed


%----------------------------------------------------------------------------
function delete_fig

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

       input_subject_pos = get(gcbf,'position');

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

    return;


%----------------------------------------------------------------------------
function subj_init_edit

    init_value = str2num(get(gcbo,'string'));

    if init_value < 0 | round(init_value) ~= init_value
%        msg = 'Only none zero integer is accepted here.';
%        set(findobj(gcf,'Tag','MessageLine'),'String',msg);
%        set(gcbo,'string','3');
        set(gcbo,'string','-1');
    end

    return;

⌨️ 快捷键说明

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