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

📄 erp_input_diff_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 2 页
字号:
   top_couple_idx = getappdata(gcf,'top_couple_idx');

   couple_hdls = getappdata(gcf,'couple_hlist');
   rows = getappdata(gcf,'NumRows');

   num_couple = size(curr_couple_lst, 1);
   couple_idx = top_couple_idx;
   last_row = 0;

   for i=1:rows
      c_hdls = couple_hdls(i,:);
      if (couple_idx <= num_couple),
         set(c_hdls(1),'string',sprintf('%d.',couple_idx),'visible','on');
         set(c_hdls(2),'value',curr_couple_lst(couple_idx,1),'visible','on');
         set(c_hdls(3),'visible','on');
         set(c_hdls(4),'value',curr_couple_lst(couple_idx,2),'visible','on');
         set(c_hdls(5),'string','Delete','visible','on');

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

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

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

   return;						% DisplayCouple


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

%   edit_cbf = 'erp_input_diff_ui(''EDIT_DIFF'');';
   edit_cbf = 'set(findobj(gcf,''Tag'',''MessageLine''),''string'',';
   edit_cbf = [edit_cbf, '''Use Add Button to add condition couple'');'];

   couple_template = getappdata(gcf,'couple_template');
   a_hdls = copyobj(couple_template,gcf);


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

   set(a_hdls(2),'String',[' '],'Enable','off','Background',[0.9 0.9 0.9], ...
		 'Visible','off','buttondown',edit_cbf);

   set(a_hdls(3),'String','-','Enable','on','Background',[0.8 0.8 0.8], ...
		 'Visible','off');

   set(a_hdls(4),'String',[' '],'Enable','off','Background',[0.9 0.9 0.9], ...
		 'Visible','off','buttondown',edit_cbf);

   set(a_hdls(5),'String','Add','Visible','off', ...
		     'callback','erp_input_diff_ui(''ADD_DIFF'');');

   setappdata(gcf,'AddRowHdls',a_hdls);

   return;						% CreateAddRow


%----------------------------------------------------------------------------
function ShowAddRow(couple_idx,v_pos,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(1),'Visible','On','String',sprintf('%d.',couple_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 UpdateCouple(couple_idx)
function UpdateCouple

   curr_couple_lst = getappdata(gcf,'curr_couple_lst');
   couple_hdls = getappdata(gcf,'couple_hlist');

   user_idx = get(gcbo,'UserData');
   row_idx = user_idx(1);
   col_idx = user_idx(2);
   col2_idx = 2 - col_idx + 1;
   couple_idx = str2num(get(couple_hdls(row_idx,1),'String'));
   old_value = curr_couple_lst(couple_idx,col_idx);
   curr_couple_lst(couple_idx,col_idx) = get(gcbo,'value');

   if curr_couple_lst(couple_idx,col_idx) == curr_couple_lst(couple_idx,col2_idx)
      set(findobj(gcbf,'Tag','MessageLine'),'String', ...
	'Choose different condition for difference');
      set(gcbo,'value',old_value);
      return;
   end

   setappdata(gcf,'curr_couple_lst',curr_couple_lst);

   return;						% UpdateCouple


%----------------------------------------------------------------------------
function DeleteCouple()

   curr_couple_lst = getappdata(gcf,'curr_couple_lst');
   couple_hdls = getappdata(gcf,'couple_hlist');

   row_idx = get(gcbo,'UserData');
   couple_idx = str2num(get(couple_hdls(row_idx,1),'String'));

   mask = ones(1,size(curr_couple_lst,1));  mask(couple_idx) = 0;
   idx = find(mask == 1);
   curr_couple_lst = curr_couple_lst(idx,:);

   setappdata(gcf,'curr_couple_lst',curr_couple_lst);

   DisplayCouple;
   UpdateSlider;

   return;						% DeleteCouple


%----------------------------------------------------------------------------
function AddCouple()

   curr_couple_lst = getappdata(gcf,'curr_couple_lst');
   rows = getappdata(gcf,'NumRows');
   a_hdls = getappdata(gcf,'AddRowHdls');
   couple_idx = str2num(get(a_hdls(1),'String'));
   num_couple = size(curr_couple_lst,1);

   num_couple = num_couple + 1;
   curr_couple_lst(num_couple,1) = 1;
   curr_couple_lst(num_couple,2) = 1;

   setappdata(gcf,'curr_couple_lst',curr_couple_lst);

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

   if (new_couple_row == rows),  	% the new couple row is the last row
      top_couple_idx = getappdata(gcf,'top_couple_idx');
      setappdata(gcf,'top_couple_idx',top_couple_idx+1);
   end;

   DisplayCouple;

   couple_hdls = getappdata(gcf,'couple_hlist');

   if (new_couple_row == rows),  	% the new couple row is the last row
      set(gcf,'CurrentObject',couple_hdls(rows-1,2));
   else
      set(gcf,'CurrentObject',couple_hdls(new_couple_row,2));
   end;

   UpdateSlider;

   return;						% AddCouple


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

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

   top_couple_idx = total_rows - curr_value + 1;

   setappdata(gcf,'top_couple_idx',top_couple_idx);

   DisplayCouple;

   return;						% MoveSlider


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

   couple_hdls = getappdata(gcf,'couple_hlist');
   top_pos = get(couple_hdls(1,3),'Position');
   bottom_pos = get(couple_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_couple_idx = getappdata(gcf,'top_couple_idx');
   rows = getappdata(gcf,'NumRows');

   curr_couple_lst = getappdata(gcf,'curr_couple_lst');
   num_couple = size(curr_couple_lst,1);

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

   if (num_couple ~= 0)		% don't need to update when no couple
      set(slider_hdl,'Min',1,'Max',total_rows, ...
                  'Value',total_rows-top_couple_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_diff_pos = get(gcbf,'position');

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

    return;


%----------------------------------------------------------------------------
function click_ok

   h01 = gcbf;
   h0 = getappdata(h01,'main_fig');
   datamat_file = getappdata(h0,'datamat_file');  % get filename for setting
   setting = getappdata(h0,'setting');

   new_couple_lst = getappdata(h01,'curr_couple_lst') - 1;

   %  get rid of 0 in new_couple_lst
   %
   [r c] = find(~new_couple_lst);
   mask = ones(size(new_couple_lst,1),1);
   mask(r) = 0;
   new_couple_lst = new_couple_lst(find(mask),:);

   setting.cond_couple_lst = new_couple_lst;
   old_setting = getappdata(h0, 'setting');

   if isequal(setting,old_setting)		%  nothing was changed
      close(h01);
      return;
   end

   try
      setting2 = setting;
      save(datamat_file, '-append', 'setting2');
   catch
      msg = 'Cannot save setting information';
      set(findobj(h01,'Tag','MessageLine'),'String',['ERROR: ', msg]);
      return;
   end;

   wave_amplitude = getappdata(h0,'org_wave_amplitude');
   [dim1 dim2 dim3] = size(wave_amplitude);

   if ~isempty(new_couple_lst)
      for i = 1:size(new_couple_lst,1)
         wave_amplitude(:,:,dim3+i) = ...
		wave_amplitude(:,:,new_couple_lst(i,1)) - ...
		wave_amplitude(:,:,new_couple_lst(i,2));
      end
   end

   org_selected_wave = getappdata(h0,'org_selected_wave');
   org_wave_name = getappdata(h0,'org_wave_name');
   mean_wave_name = getappdata(h0,'mean_wave_name');

   selected_wave = [org_selected_wave ...
	length(org_selected_wave)+[1:length(mean_wave_name)] ...
	length(org_selected_wave)+length(mean_wave_name)+[1:size(new_couple_lst,1)]];
%	[org_selected_wave length(org_selected_wave)+[1:size(new_couple_lst,1)]];

   wave_selection = getappdata(h0,'wave_selection');
   wave_selection = wave_selection(find(wave_selection <= length(org_selected_wave)));
   wave_selection = ...
	[wave_selection length(org_selected_wave)+length(mean_wave_name)+[1:size(new_couple_lst,1)]];

   wave_name = [org_wave_name, mean_wave_name];

   %  couple name
   %
   couple_name = cell(1,size(new_couple_lst,1));

   for i = 1:size(new_couple_lst,1)
      couple_name{i} = ...
	[wave_name{new_couple_lst(i,1)} ' - ' wave_name{new_couple_lst(i,2)}];
%	['cond' num2str(new_couple_lst(i,1)) ' - cond' num2str(new_couple_lst(i,2))];
   end

   wave_name = [wave_name, couple_name];

   setappdata(h0,'wave_amplitude',wave_amplitude);
   setappdata(h0,'selected_wave',selected_wave);
   setappdata(h0,'wave_selection',wave_selection);
   setappdata(h0,'wave_name',wave_name);
   setappdata(h0,'cond_couple_lst',new_couple_lst);

   setappdata(h0,'setting',setting);
   setappdata(h0,'init_option',[]);

   close(h01);

   old_pointer0 = get(h0,'pointer');
   set(h0,'pointer','watch');

   erp_showplot_ui(h0);

   set(h0,'pointer',old_pointer0);

   return;					% click_ok

⌨️ 快捷键说明

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