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

📄 rri_input_contrast_ui.m

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

   ax_hdl = axes('Parent',h0, ...
	 'units', 'normal', ...
	 'Position', pos, ...
	 'box','on', ...
	 'XTick',[], 'YTick', []);
	
   %---------------------------- figure menu ------------------------------

   h_file = uimenu('Parent',h0, ...
        'Label', '&File', ...
        'Tag', 'FileMenu');
   m1 = uimenu(h_file, ...
        'Label', '&Load', ...
        'Callback','rri_input_contrast_ui(''MENU_LOAD_CONTRASTS'');', ...
	'visible','off', ...
        'Tag', 'LoadContrasts');
   m1 = uimenu(h_file, ...
        'Label', '&Save', ...
        'Callback','rri_input_contrast_ui(''MENU_SAVE_CONTRASTS'');', ...
	'visible','off', ...
        'Tag', 'SaveContrasts');
   m1 = uimenu(h_file, ...
        'Label', 'S&ave as', ...
        'Callback','rri_input_contrast_ui(''MENU_SAVE_AS_CONTRASTS'');', ...
	'visible','off', ...
        'Tag', 'SaveAsContrasts');
%	'separator', 'on', ...
%        'Label', 'L&oad from text file', ...
%        'Label', 'Sa&ve to text file as', ...
   m1 = uimenu(h_file, ...
        'Label', '&Load', ...
        'Callback','rri_input_contrast_ui(''MENU_LOAD_TEXT'');', ...
        'Tag', 'LoadText');
   m1 = uimenu(h_file, ...
        'Label', '&Save', ...
        'Callback','rri_input_contrast_ui(''MENU_SAVE_TEXT'');', ...
        'Tag', 'SaveText');
   m1 = uimenu(h_file, ...
        'Label', 'S&ave as', ...
        'Callback','rri_input_contrast_ui(''MENU_SAVE_AS_TEXT'');', ...
        'Tag', 'SaveAsText');
   m1 = uimenu(h_file, ...
        'Label', '&Using Helmert Matrix', ...
        'Callback','rri_input_contrast_ui(''MENU_HELMERT_MATRIX'');', ...
	'separator', 'on', ...
        'Tag', 'HelmertMatrix');
   m1 = uimenu(h_file, ...
        'Label', '&Close', ...
        'Callback','rri_input_contrast_ui(''MENU_CLOSE_CONTRASTS'');', ...
	'separator', 'on', ...
        'Tag', 'CloseContrasts');

   h_file = uimenu('Parent',h0, ...
        'Label', '&Edit', ...
        'Tag', 'EditMenu');
   m1 = uimenu(h_file, ...
        'Label', '&Clear', ...
        'Callback','rri_input_contrast_ui(''MENU_CLEAR_CONTRASTS'');', ...
        'Tag', 'ClearContrasts');

   h_file = uimenu('Parent',h0, ...
        'Label', '&Condition', ...
	'visible', 'off', ...
        'Tag', 'ConditionMenu');
   m1 = uimenu(h_file, ...
        'Label', '&Load', ...
        'Callback','rri_input_contrast_ui(''MENU_LOAD_CONDITIONS'');', ...
        'Tag', 'LoadConditions');

   %  Help submenu
   %
   Hm_topHelp = uimenu('Parent',h0, ...
           'Label', '&Help', ...
           'Tag', 'Help');
   Hm_how = uimenu('Parent',Hm_topHelp, ...
           'Label', '&How to use this window?', ...
           'Callback','rri_helpfile_ui(''rri_input_contrast_hlp.txt'',''How to use it'');', ...
	   'visible', 'off', ...
           'Tag', 'How');
   Hm_new = uimenu('Parent',Hm_topHelp, ...
           'Label', '&What''s new', ...
	   'Callback','rri_helpfile_ui(''whatsnew.txt'',''What''''s new'');', ...
           'Tag', 'New');
   Hm_about = uimenu('Parent',Hm_topHelp, ...
           'Label', '&About this program', ...
           'Tag', 'About', ...
           'CallBack', 'plsgui_version');

   pause(0.01)

   % save handles for contrast#1
   contrast1_hdls = [c_h1,c_h2,c_h3,c_h4,c_h5];  	
   setappdata(h0,'Contrast_hlist',contrast1_hdls);

   contrast_template = copyobj(contrast1_hdls,h0);
   for i=1:length(contrast_template),
      set(contrast_template(i),'visible','off','Tag', sprintf('Template%d',i));
   end;

   setappdata(h0,'prefix',prefix);
   setappdata(h0,'OldContrasts',old_contrasts);
   setappdata(h0,'CurrContrasts',old_contrasts);
   setappdata(h0,'ContrastTemplate',contrast_template);
   setappdata(h0,'ContrastHeight',.105);
   setappdata(h0,'TopContrastIdx',1);

   setappdata(h0,'ContrastFile','');
   setappdata(h0,'PlotAxes',ax_hdl);
   setappdata(h0,'ViewOnly',view_only);
   setappdata(h0,'num_groups',num_groups);

   SetupContrastRows;
   SetupSlider;
   CreateAddRow;
   DisplayContrasts;
   UpdateSlider;

   LoadConditions(prefix,pls_session,cond_selection);

   if ~isempty(design)
      LoadContrasts(design);
      DisplayContrasts;
      UpdateSlider;
      ShowGroups;
      ShowConditions;
   end

%   setappdata(h0,'Conditions',conditions);

   if (view_only),
      HideMenuEntries;
   end;

   fig_hdl = h0;

   return;						% init


%----------------------------------------------------------------------------
function SetupContrastRows()

   contrast_template = getappdata(gcf,'ContrastTemplate');
   contrast_hdls = getappdata(gcf,'Contrast_hlist');
   contrast_h = getappdata(gcf,'ContrastHeight');
   a_hdls = getappdata(gcf,'AddRowHdls');

   button_pos = get(findobj(gcf,'Tag','ContrastFrame'),'Position');
   top_pos = get(contrast_hdls(1,1),'Position');

   rows = floor(( top_pos(2) - button_pos(2) ) / contrast_h);
   v_pos = top_pos(2) - [0:rows-1]*contrast_h;

   edit_name_cbf = 'rri_input_contrast_ui(''UPDATE_CONTRAST_NAME'');';
   delete_cbf = 'rri_input_contrast_ui(''DELETE_CONTRAST'');';
   edit_value_cbf = 'rri_input_contrast_ui(''UPDATE_CONTRAST_VALUE'');';
   plot_cbf = 'rri_input_contrast_ui(''PLOT_CONTRAST'');';

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

   v = 'on';
   for i=1:rows,

      new_c_hdls = contrast_hdls(i,:);

      pos = get(contrast_hdls(1,1),'Position');
      pos(2) = v_pos(i);
      set(new_c_hdls(1),'String','?','Position',pos,'Visible',v, ...
			'UserData',i);

      pos = get(contrast_hdls(1,2),'Position');
      pos(2) = v_pos(i);
      set(new_c_hdls(2),'String','', 'Position',pos, 'Visible',v, ...
                        'UserData',i,'Callback',edit_name_cbf);

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

      pos = get(contrast_hdls(1,4),'Position');
      pos(2) = v_pos(i)-.05;
      set(new_c_hdls(4),'String','', 'Position',pos, 'Visible',v, ...
                        'UserData',i,'Callback',edit_value_cbf);

      pos = get(contrast_hdls(1,5),'Position');
      pos(2) = v_pos(i)-.05;
      set(new_c_hdls(5),'String','Plot','Position',pos,'Visible',v, ...
                        'UserData',i,'Callback',plot_cbf);

   end;

   %  set up for the Add row
   for i=1:length(a_hdls),
      new_pos = get(contrast_hdls(1,i),'Position');
      set(a_hdls(i),'Position',new_pos);
   end;

   setappdata(gcf,'Contrast_hlist',contrast_hdls);
   setappdata(gcf,'NumRows',rows);

   return;					% SetupContrastRows


%----------------------------------------------------------------------------
function DisplayContrasts()

   g = get(findobj(gcf,'Tag','GroupListBox'),'value');
   CurrContrast = getappdata(gcf,'CurrContrasts');

   if ~isempty(CurrContrast) & length(CurrContrast) >= g
      curr_contrast = CurrContrast{g};
   else
      curr_contrast = [];
   end

   top_contrast_idx = getappdata(gcf,'TopContrastIdx');
   contrast_hdls = getappdata(gcf,'Contrast_hlist');
   rows = getappdata(gcf,'NumRows');
   view_only = getappdata(gcf,'ViewOnly');

   num_contrast = length(curr_contrast);

   last_row = 0;
   contrast_idx = top_contrast_idx;
   for i=1:rows
      c_hdls = contrast_hdls(i,:);
      if (contrast_idx <= num_contrast),
         contrast_name = curr_contrast(contrast_idx).name;
         contrast_values = curr_contrast(contrast_idx).value;
         contrast_values_str = Number2String(contrast_values);

         set(c_hdls(1),'String',sprintf('%d.',contrast_idx),'Visible','on');
         set(c_hdls(2),'String',sprintf('%s',contrast_name),'Visible','on');
         if (view_only)
             set(c_hdls(3),'String','Delete','Visible','off');
         else
             set(c_hdls(3),'String','Delete','Visible','on');
         end;
         set(c_hdls(4),'String',contrast_values_str,'Visible','on');
         set(c_hdls(5),'String','Plot','Visible','on');


         contrast_idx = contrast_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','','Visible','off');
         set(c_hdls(5),'String','Plot','Visible','off');
      end;
   end;

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

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

   return;						% DisplayContrasts


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

   contrast_template = getappdata(gcf,'ContrastTemplate');

   a_hdls = copyobj(contrast_template,gcf);

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

%   set(a_hdls(2),'String','< Contrast Name >','Enable','on', ...
   set(a_hdls(2),'String','','Enable','on', ...
		 'HorizontalAlignment','left', ...
                 'Foreground',[0 0 0], ...
                 'Background',[0.7 0.7 0.7],'Visible','off');
%                 'Background',[1 1 1],'Visible','off');

   set(a_hdls(3),'String','Add','Enable','on', 'Visible','off', ...
		     'Callback','rri_input_contrast_ui(''ADD_CONTRAST'');');

   set(a_hdls(4),'String','< Contrast Values >','Enable','on', ...
		 'HorizontalAlignment','left', ...
                 'Foreground',[0 0 0], ...
                 'Background',[1 1 1],'Visible','off');

   set(a_hdls(5),'String','Plot','Enable','off','Visible','off','Callback','');

   setappdata(gcf,'AddRowHdls',a_hdls);

   return;						% CreateAddRow


%----------------------------------------------------------------------------
function ShowAddRow(contrast_idx,pos,row_idx)

   a_hdls = getappdata(gcf,'AddRowHdls');

   v_pos = [pos pos pos pos-.05 pos-.05];

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

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

%   set(a_hdls(2),'string','<Contrast Name>');
   set(a_hdls(4),'string','<Contrast Value>');

   set(a_hdls(1),'String',sprintf('%d.',contrast_idx),'UserData',row_idx);
   set(a_hdls(2),'string',['Contrast ', num2str(contrast_idx)]);
   set(a_hdls(3),'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 UpdateContrastName(contrast_idx)

   view_only = getappdata(gcf,'ViewOnly');

   g = get(findobj(gcf,'Tag','GroupListBox'),'value');
   CurrContrast = getappdata(gcf,'CurrContrasts');

   if ~isempty(CurrContrast) & length(CurrContrast) >= g
      curr_contrast = CurrContrast{g};
   else
      curr_contrast = [];
   end

   contrast_hdls = getappdata(gcf,'Contrast_hlist');

   row_idx = get(gcbo,'UserData');
   contrast_idx = str2num(get(contrast_hdls(row_idx,1),'String'));

   if (view_only),		% don't allow changing contrast name 
      set(gcbo,'String',curr_contrast(contrast_idx).name); 
      msg = 'ERROR: Contrast name cannot be changed.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   end;

   curr_contrast(contrast_idx).name = deblank(get(gcbo,'String'));

   CurrContrast{g} = curr_contrast;
   setappdata(gcf,'CurrContrasts',CurrContrast);

   return;						% UpdateContrastName

%----------------------------------------------------------------------------
function UpdateContrastValue(contrast_idx)

   view_only = getappdata(gcf,'ViewOnly');

   g = get(findobj(gcf,'Tag','GroupListBox'),'value');
   CurrContrast = getappdata(gcf,'CurrContrasts');

   if ~isempty(CurrContrast) & length(CurrContrast) >= g
      curr_contrast = CurrContrast{g};
   else
      curr_contrast = [];
   end

   contrast_hdls = getappdata(gcf,'Contrast_hlist');
   conditions = getappdata(gcf,'Conditions');

   row_idx = get(gcbo,'UserData');
   contrast_idx = str2num(get(contrast_hdls(row_idx,1),'String'));

   if (view_only),		% don't allow changing contrast name 
      contrast_values = curr_contrast(contrast_idx).value;
      contrast_values_str = Number2String(contrast_values);
      set(gcbo,'String',contrast_values_str);

      msg = 'ERROR: Contrast values cannot be changed.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
     return;
   end;

   contrast_values = str2num(get(gcbo,'String'));

   if isempty(contrast_values)
      msg = 'ERROR: Invalid contrast values.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   end;

   if length(conditions) ~= length(contrast_values),
      msg = 'ERROR: The number of contrast values does not match the number of conditions.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   end;


   curr_contrast(contrast_idx).value = contrast_values;

if 0	% verify before save
   % verify the contrasts are linear independent
   %
   num_contrasts = length(curr_contrast);
   contrast_mat = []; 
   for i=1:num_contrasts;
     if ~isempty(curr_contrast(i).value) 
        contrast_mat = [contrast_mat; curr_contrast(i).value];
     end;
   end;

   if (rank(contrast_mat) ~= size(contrast_mat,1))
      msg = 'ERROR:  The specified contrast is not linear independent to the others.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   end;
end

   CurrContrast{g} = curr_contrast;
   setappdata(gcf,'CurrContrasts',CurrContrast);

   PlotContrast;

   return;						% UpdateContrastValue


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

⌨️ 快捷键说明

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