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

📄 rri_input_subject_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 2 页
字号:
%RRI_INPUT_SUBJECT_UI Form to input subjects
%
%   Usage: [subjects, subj_files, num_subj_init, img_ext] = ...
%	rri_input_subject_ui(old_subjects, old_subj_files, ...
%	condition, selected_conditions, num_subj_init, img_ext)
%

%   I (old_subjects) - old subjects, or action word to call itself recursively.
%   I (old_subj_files) - Saved ImageFile matrix.
%   I (condition) - all the condition names.
%   I (selected_conditions) - index of selected conditions.
%   I (num_subj_init) - Number of characters for subject initial
%   I (img_ext) - filter (img file extension)
%   O (subjects) - new subjects array
%   O (subj_img) - Subject-ImageFile matrix
%   O (num_subj_init) - Number of characters for subject initial
%   O (img_ext) - filter (img file extension)
%
%   Modified on 23-SEP-2002 by Jimmy Shen
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [subjects, subj_files, num_subj_init, filter] = rri_input_subject_ui(varargin)

   if nargin == 0 | ~ischar(varargin{1})
      old_subjects = varargin{1};  
      old_subj_files = varargin{2};
      condition = varargin{3};
      selected_conditions = varargin{4};
      num_subj_init = varargin{5};

      if nargin > 5
         filter = varargin{6};
      else
         filter = '*';
      end

      init(old_subjects, num_subj_init, filter);

      setappdata(gcf,'old_subj_files',old_subj_files);
      setappdata(gcf,'subj_files',old_subj_files);
      setappdata(gcf,'condition',condition);
      setappdata(gcf,'selected_conditions',selected_conditions);
      setappdata(gcf,'SessionPLSDir',getappdata(gcbf, 'SessionPLSDir'));

      uiwait;				% wait for user finish 

      subjects = getappdata(gcf,'CurrSubjects');
      subj_files = getappdata(gcf,'subj_files');
      filter = getappdata(gcf,'filter');
      h = findobj(gcf,'Tag','SubjectInitEdit');
      if ~isempty(h)
         num_subj_init = str2num(get(h, 'string'));
      end

      close(gcf);
      return;
   end;

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

   action = upper(varargin{1});

   if strcmp(action,'UPDATE_SUBJECT'),
      UpdateSubject;
   elseif strcmp(action,'DELETE_SUBJECT'),
      DeleteSubject;
   elseif strcmp(action,'ADD_SUBJECT'),
      AddSubject;
   elseif strcmp(action,'EDIT_SUBJECT'),
      EditSubject;
   elseif strcmp(action,'BUTTONDOWN_SUBJECTS'),
      msg = 'Use Add button to add the subject';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
   elseif strcmp(action,'MOVE_SLIDER'),
      MoveSlider;
   elseif strcmp(action,'SUBJ_INIT_EDIT'),
      subj_init_edit;
   elseif strcmp(action,'DELETE_FIG'),
      delete_fig;
   elseif strcmp(action,'TOGGLE_FULL_PATH'),
      SwitchFullPath;
   elseif strcmp(action,'CANCEL_BUTTON_PRESSED'),
      old_subjects = getappdata(gcf,'OldSubjects');
      old_subj_files = getappdata(gcf,'old_subj_files');

      setappdata(gcf,'CurrSubjects',old_subjects);
      setappdata(gcf,'subj_files',old_subj_files);

      uiresume;
   elseif strcmp(action,'DONE_BUTTON_PRESSED'),
      DoneButtonPressed;
   end;

   return;


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

function init(old_subjects, num_subj_init, filter)

   save_setting_status = 'on';
   input_subject_pos = [];

   try
      load('pls_profile');
   catch
   end

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

      pos = input_subject_pos;

   else

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

      pos = [x y w h];

   end

   h0 = figure('Color',[0.8 0.8 0.8], ...
   	'Units','normal', ...
        'Name','Edit Subject Directory', ...
        'MenuBar','none', ...
        'NumberTitle','off', ...
        'deletefcn','rri_input_subject_ui(''DELETE_FIG'');', ...
   	'Position',pos, ...
        'WindowStyle', 'modal', ...
   	'Tag','InputSubject', ...
   	'ToolBar','none');

   x = 0.06;
   y = 0.9;
   w = 1;
   h = 0.06;

   pos = [x y w h];

   c = uicontrol('Parent',h0, ...		% subject label
   	'Style','text', ...
   	'Units','normal', ...
   	'BackgroundColor',[0.8 0.8 0.8], ...
   	'FontUnits','normal', ...
   	'FontSize',0.6, ...
	'FontName', 'FixedWidth', ...
   	'FontAngle','italic', ...
   	'FontWeight','bold', ...
   	'HorizontalAlignment','left', ...
   	'Position',pos, ...
   	'String','Subjects Directory: ', ...
   	'Tag','SubjectTitleLabel');

   x = 0.03;
   y = 0.83;
   w = 0.07;

   pos = [x y w h];

   c_h1 = uicontrol('Parent',h0, ...		% subject idx
   	'Style','text', ...
   	'Units','normal', ...
   	'BackgroundColor',[0.8 0.8 0.8], ...
   	'FontUnits','normal', ...
   	'FontSize',0.5, ...
   	'HorizontalAlignment','right', ...
   	'Position',pos, ...
   	'String','1.', ...
   	'Tag','SubjectIdxLabel');

   x = x+w+0.01;
   w = 0.5;

   pos = [x y w h];

   c_h2 = uicontrol('Parent',h0, ...		% subject name
   	'Style','edit', ...
   	'Units','normal', ...
   	'BackgroundColor',[0.9 0.9 0.9], ...
   	'FontUnits','normal', ...
   	'FontSize',0.5, ...
   	'HorizontalAlignment','left', ...
   	'Position',pos, ...
   	'String','', ...
	'Enable','Inactive',...
   	'Tag','SubjectNameEdit');

   x = x+w+0.01;
   w = 0.12;

   pos = [x y w h];

   c_h3 = uicontrol('Parent',h0, ...		% subject add/delete button
   	'Units','normal', ...
   	'Position',pos, ...
   	'FontUnits','normal', ...
   	'FontSize',0.5, ...
   	'String','Add ...', ...
   	'Tag','ADD/DELButton');

   x = x+w+0.01;

   pos = [x y w h];

   c_h4 = uicontrol('Parent',h0, ...		% subject edit button
   	'Units','normal', ...
   	'Position',pos, ...
   	'FontUnits','normal', ...
   	'FontSize',0.5, ...
   	'String','Edit ...', ...
   	'Tag','EDITButton');

   x = x+w+0.02;
   w = 0.04;

   pos = [x y w h];

   h1 = uicontrol('Parent',h0, ...		% scroll bar
	'Style', 'slider', ...
   	'Units','normal', ...
   	'Min',1, ...
   	'Max',20, ...
   	'Value',20, ...
   	'Position',pos, ...
   	'Callback','rri_input_subject_ui(''MOVE_SLIDER'');', ...
   	'Tag','SubjSlider');

   x = 0.11;
   y = 0.15-0.01;
   w = 0.52;

   pos = [x y w h];

   h1 = uicontrol('Parent',h0, ...		% Subject Init. Label
	'Style','text', ...
        'Units','normal', ...
        'BackgroundColor',[0.8 0.8 0.8], ...
   	'FontUnits','normal', ...
   	'FontSize',0.5, ...
        'ListboxTop',0, ...
	'Value', 0, ...
        'Position',pos, ...
        'HorizontalAlignment','left', ...
        'String','Number of characters for subject initial:', ...
        'Tag','SubjectInitLabel');

   ext = get(h1, 'extent');
   w = ext(3);
   pos(3) = w;
   set(h1, 'position', pos);

   x = x+w+0.01;
   y = 0.15;
   w = 0.05;

   pos = [x y w h];

   h1 = uicontrol('Parent',h0, ...		% Subject Init. Edit
	'Style','edit', ...
        'Units','normal', ...
        'BackgroundColor',[1 1 1], ...
   	'FontUnits','normal', ...
   	'FontSize',0.5, ...
        'ListboxTop',0, ...
	'Value', 0, ...
        'Position',pos, ...
        'HorizontalAlignment','left', ...
        'String',num2str(num_subj_init), ...
        'Callback','rri_input_subject_ui(''SUBJ_INIT_EDIT'');', ...
        'Tag','SubjectInitEdit');

   x = 0.67;
   w = 0.2;

   pos = [x y w h];

   h1 = uicontrol('Parent',h0, ...		% Full Path Checkbox
	'Style','checkbox', ...
        'Units','normal', ...
        'BackgroundColor',[0.8 0.8 0.8], ...
   	'FontUnits','normal', ...
   	'FontSize',0.5, ...
        'ListboxTop',0, ...
	'Value', 0, ...
        'Position',pos, ...
        'HorizontalAlignment','left', ...
        'String','Full Path', ...
        'Callback','rri_input_subject_ui(''TOGGLE_FULL_PATH'');', ...
        'Tag','FullPathChkbox');

   x = 0.11;
   y = 0.08;

   pos = [x y w h];

   h1 = uicontrol('Parent',h0, ...			% DONE
        'Units','normal', ...
        'Callback','', ...
   	'FontUnits','normal', ...
   	'FontSize',0.5, ...
        'Position',pos, ...
        'String','DONE', ...
   	'Callback','rri_input_subject_ui(''DONE_BUTTON_PRESSED'');', ...
        'Tag','DONEButton');

   x = 0.67;

   pos = [x y w h];

   h1 = uicontrol('Parent',h0, ...			% CANCEL
        'Units','normal', ...
        'Callback','', ...
   	'FontUnits','normal', ...
   	'FontSize',0.5, ...
        'Position',pos, ...
        'String','CANCEL', ...
   	'Callback','rri_input_subject_ui(''CANCEL_BUTTON_PRESSED'');', ...
        'Tag','CANCELButton');

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

   pos = [x y w h];

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

   subj1_hdls = [c_h1,c_h2,c_h3,c_h4];  	% save handles for subject#1
   setappdata(h0,'Subj_hlist',subj1_hdls);

   subj_template = copyobj(subj1_hdls,h0);
   set(subj_template,'visible','off');

   setappdata(h0,'OldSubjects',old_subjects);
   setappdata(h0,'CurrSubjects',old_subjects);
   setappdata(h0,'SubjectTemplate',subj_template);

   subj_h = 0.06;
   setappdata(h0,'SubjectHeight',subj_h);

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

   setappdata(h0,'TopSubjectIdx',1);
   setappdata(h0,'SubjectMap',[1:length(old_subjects)]);
   setappdata(h0,'full_path', 0);
   setappdata(h0,'filter', filter);

   SetupSubjectRows;
   SetupSlider;
   CreateAddRow;
   DisplaySubjects(0);
   UpdateSlider;

   return;						% init


%----------------------------------------------------------------------------
function SetupSubjectRows()

   subj_hdls = getappdata(gcf,'Subj_hlist');
   subj_h = getappdata(gcf,'SubjectHeight');
   lower_h = getappdata(gcf,'lower_h');

   bottom_pos = get(findobj(gcf,'Tag','SubjectInitLabel'),'Position');
   top_pos = get(subj_hdls(1,2),'Position');

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

   subj_template = getappdata(gcf,'SubjectTemplate');
   edit_cbf = 'rri_input_subject_ui(''UPDATE_SUBJECT'');';
   delete_cbf = 'rri_input_subject_ui(''DELETE_SUBJECT'');';
   detail_cbf = 'rri_input_subject_ui(''EDIT_SUBJECT'');';
   buttondown_subject = 'rri_input_subject_ui(''BUTTONDOWN_SUBJECTS'');';

   nr = size(subj_hdls,1);		% nr = 1 for the initial
   if (rows < nr)			% too many rows
      for i=rows+1:nr,
          delete(subj_hdls(i,:));
      end;
      subj_hdls = subj_hdls(1:rows,:);
   else					% add new rows
      for i=nr+1:rows,
         new_c_hdls = copyobj(subj_template,gcf);
         subj_hdls = [subj_hdls; new_c_hdls'];
      end;
   end;

   v = 'Off';
   for i=1:rows,
      % take out the handle list created above, and use it in the following 'label,edit,delete'.
      % those handles are valid, since they are all obtained from function copyobj() above.
      new_c_hdls = subj_hdls(i,:);

      % init label
      pos = get(new_c_hdls(1),'Position'); pos(2) = v_pos(i)-0.01;
      set(new_c_hdls(1),'String','','Position',pos,'Visible',v,'UserData',i);

      % init each edit box setup, insert callback property while doing setup
      pos = get(new_c_hdls(2),'Position'); pos(2) = v_pos(i);
      set(new_c_hdls(2),'String','', 'Position',pos, 'Visible',v, ...
                        'UserData',i,'ButtonDownFcn',buttondown_subject);

      % init each delete button setup, insert callback property while doing setup
      pos = get(new_c_hdls(3),'Position'); pos(2) = v_pos(i);
      set(new_c_hdls(3),'String','Delete','Position',pos,'Visible',v, ...
                        'UserData',i,'Callback',delete_cbf);

      % init each edit button setup, insert callback property while doing setup
      pos = get(new_c_hdls(4),'Position'); pos(2) = v_pos(i);
      set(new_c_hdls(4),'String','Edit ...','Position',pos,'Visible',v, ...
                        'UserData',i,'Callback',detail_cbf);

   end;

   setappdata(gcf,'Subj_hlist',subj_hdls);
   setappdata(gcf,'NumRows',rows);

   return;					% SetupSubjectRows


%----------------------------------------------------------------------------
function DisplaySubjects(full_path)

   curr_subj = getappdata(gcf,'CurrSubjects');
   top_subj_idx = getappdata(gcf,'TopSubjectIdx');
   subj_map = getappdata(gcf,'SubjectMap');

   subj_hdls = getappdata(gcf,'Subj_hlist');
   rows = getappdata(gcf,'NumRows');

   num_subj = length(curr_subj);
   subj_idx = top_subj_idx;
   last_row = 0;

⌨️ 快捷键说明

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