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

📄 rri_input_condition_ui.m

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

   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 = cond_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,'Callback',edit_cbf);

      % 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);

   end

   setappdata(gcf,'Cond_hlist',cond_hdls);
   setappdata(gcf,'NumRows',rows);

   return;					% SetupConditionRows


%----------------------------------------------------------------------------
function DisplayConditions()

   curr_cond = getappdata(gcf,'CurrConditions');
   top_cond_idx = getappdata(gcf,'TopConditionIdx');

   cond_hdls = getappdata(gcf,'Cond_hlist');
   rows = getappdata(gcf,'NumRows');

   num_cond = length(curr_cond);
   cond_idx = top_cond_idx;
   last_row = 0;

   for i=1:rows
      c_hdls = cond_hdls(i,:);
      if (cond_idx <= num_cond),
         set(c_hdls(1),'String',sprintf('%d.',cond_idx),'Visible','on');
         set(c_hdls(2),'String',sprintf('%s',curr_cond{cond_idx}), ...
                       'Visible','on');
         set(c_hdls(3),'String','Delete','Visible','on');

         cond_idx = cond_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');
      end;
   end;

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

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

   return;						% DisplayConditions


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

   cond_template = getappdata(gcf,'ConditionTemplate');

   a_hdls = copyobj(cond_template,gcf);

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

   set(a_hdls(2),'String','','Enable','on','Background',[1 1 1], ...
		 'Visible','off');

   set(a_hdls(3),'String','Add','Visible','off', ...
		     'Callback','rri_input_condition_ui(''ADD_CONDITION'');');

   setappdata(gcf,'AddRowHdls',a_hdls);

   return;						% CreateAddRow


%----------------------------------------------------------------------------
function ShowAddRow(cond_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(2),'String','');
   set(a_hdls(1),'Visible','On','String',sprintf('%d.',cond_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 UpdateCondition(cond_idx)

   curr_cond = getappdata(gcf,'CurrConditions');
   cond_hdls = getappdata(gcf,'Cond_hlist');

   row_idx = get(gcbo,'UserData');
   cond_idx = str2num(get(cond_hdls(row_idx,1),'String'));

   condname = get(gcbo,'String');
   condname = deblank(fliplr(deblank(fliplr(condname))));
   curr_cond{cond_idx} = condname;

   setappdata(gcf,'CurrConditions',curr_cond);

   return;						% UpdateCondition


%----------------------------------------------------------------------------
function DeleteCondition()

   curr_cond = getappdata(gcf,'CurrConditions');
   cond_hdls = getappdata(gcf,'Cond_hlist');
   subj_files = getappdata(gcf,'subj_files');

   row_idx = get(gcbo,'UserData');
   cond_idx = str2num(get(cond_hdls(row_idx,1),'String'));

   mask = ones(1,length(curr_cond));  mask(cond_idx) = 0;
   idx = find(mask == 1);
   curr_cond = curr_cond(idx);
   if ~isempty(subj_files)
      subj_files = subj_files(idx,:);
   end

   setappdata(gcf,'subj_files',subj_files);
   setappdata(gcf,'CurrConditions',curr_cond);

   DisplayConditions;
   UpdateSlider;

   return;						% DeleteCondition


%----------------------------------------------------------------------------
function AddCondition()

   subj_files = getappdata(gcf,'subj_files');

   if ~isempty(subj_files)
      setappdata(gcf,'reselect_subj',1);
   end
   curr_cond = getappdata(gcf,'CurrConditions');
   rows = getappdata(gcf,'NumRows');
   a_hdls = getappdata(gcf,'AddRowHdls');
   cond_idx = str2num(get(a_hdls(1),'String'));
   condname = get(a_hdls(2),'String');
   condname = deblank(fliplr(deblank(fliplr(condname))));
   num_cond = length(curr_cond);

   if isempty(condname)
      msg = 'ERROR: All conditions must have name specified.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      setappdata(gcf,'reselect_subj',0);
      return;
   end;

   for i=1:num_cond
      if(strcmp(curr_cond{i},condname))
         msg = 'ERROR: No conditions should be duplicated.';
         set(findobj(gcf,'Tag','MessageLine'),'String',msg);
         setappdata(gcf,'reselect_subj',0);
         return;
      end;
   end

   num_cond = num_cond + 1;
   curr_cond{num_cond} = condname;

   setappdata(gcf,'CurrConditions',curr_cond);

   new_cond_row = get(a_hdls(1),'UserData');

   if (new_cond_row == rows),  	% the new condition row is the last row
      top_cond_idx = getappdata(gcf,'TopConditionIdx');
      setappdata(gcf,'TopConditionIdx',top_cond_idx+1);
   end;

   subj_files = getappdata(gcf,'subj_files');
   if ~isempty(subj_files)

      %  all the 4 lines below are another approach
      %
      % old_condnum = size(subj_files,1);
      % mask = [linspace(1,old_condnum,old_condnum)';old_condnum];
      % subj_files = subj_files(mask,:);
      % setappdata(gcf,'subj_files',subj_files);

      %  all the 4 lines below are one approach
      %
      old_subjnum = size(subj_files,2);
      new_row = {' '};
      new_row = repmat(new_row, [1,old_subjnum]);
      setappdata(gcf,'subj_files',[subj_files;new_row]);

   end

   DisplayConditions;

   cond_hdls = getappdata(gcf,'Cond_hlist');
   if (new_cond_row == rows),  	% the new condition row is the last row
      set(gcf,'CurrentObject',cond_hdls(rows-1,2));
   else
      set(gcf,'CurrentObject',cond_hdls(new_cond_row,2));
   end;

   UpdateSlider;

   return;						% AddConditions


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

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

   top_cond_idx = total_rows - curr_value + 1;

   setappdata(gcf,'TopConditionIdx',top_cond_idx);

   DisplayConditions;

   return;						% MoveSlider


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

   cond_hdls = getappdata(gcf,'Cond_hlist');
   top_pos = get(cond_hdls(1,3),'Position');
   bottom_pos = get(cond_hdls(end,3),'Position');

   slider_hdl = findobj(gcf,'Tag','CondSlider');
   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_cond_idx = getappdata(gcf,'TopConditionIdx');
   rows = getappdata(gcf,'NumRows');

   curr_cond = getappdata(gcf,'CurrConditions');
   num_cond = length(curr_cond);

   total_rows = num_cond+1;
   slider_hdl = findobj(gcf,'Tag','CondSlider');

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

   return;						% UpdateSlider


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

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

   return;						% ShowSlider


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

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

   return;						% HideSlider


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

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

       input_condition_pos = get(gcbf,'position');

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

    return;

⌨️ 快捷键说明

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