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

📄 fmri_select_profiles_ui.m

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


% --------------------------------------------------------------------
function AddSessionProfile()

   h = findobj(gcf,'Tag','File/DirectoryList');    % get the selected file
   selected_dir_idx = get(h,'Value');
   dir_info = get(h,'Userdata');

   dir_entry = find([dir_info.is_dir(selected_dir_idx)] == 1);

   if isempty(dir_entry)			  % only select files 
      selected_files = dir_info.names(selected_dir_idx);
   else
      msg = 'ERROR: Cannot select a directory.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   end;

   num_files = length(selected_files); 
   full_selected_files = cell(num_files,1);
   for i=1:num_files,
      curr = pwd;
      if isempty(curr)
         curr = filesep;
      end

      full_selected_files{i} = fullfile(curr,selected_files{i});
   end;
   
   %  update the session profile list
   %
   h = findobj(gcf,'Tag','SessionProfileList');	   
   profile_list = get(h,'String');
   full_profile_list = get(h,'Userdata');

   % check for duplication
   %
   for i=1:length(full_profile_list),
     for j=1:length(selected_files),
       if isequal(full_profile_list{i},full_selected_files{j})
          msg = 'ERROR: Duplicate session profile is not allowed.';
          set(findobj(gcf,'Tag','MessageLine'),'String',msg);
          return;
       end;  
     end;
   end; 

   updated_profile_list = [profile_list; selected_files];
   updated_full_profile_list = [full_profile_list; full_selected_files];

   use_full_path = get(findobj(gcf,'Tag','FullPathChkbox'),'Value');
   if (use_full_path)
      set(h,'String',updated_full_profile_list);
   else
      set(h,'String',updated_profile_list);
   end
   set(h,'Userdata',updated_full_profile_list);

   return;					% AddSessionProfile


% --------------------------------------------------------------------
function RemoveSessionProfile()

   %  update the session profile list
   %
   h = findobj(gcf,'Tag','SessionProfileList');	   
   profile_idx = get(h,'Value');
   profile_list = get(h,'String');
   full_profile_list = get(h,'Userdata');

   mask = zeros(1,length(profile_list));
   mask(profile_idx) = 1;
   remain_idx = find(mask == 0);

   if isempty(remain_idx)
      updated_profile_list = [];
      updated_full_profile_list = [];
   else
      updated_profile_list = profile_list(remain_idx);
      updated_full_profile_list = full_profile_list(remain_idx); 
   end;

   if (profile_idx > length(updated_profile_list)) & (profile_idx ~= 1)
       set(h,'Value',profile_idx - 1);
   end;

   use_full_path = get(findobj(gcf,'Tag','FullPathChkbox'),'Value');
   if (use_full_path)
      set(h,'String',updated_full_profile_list);
   else
      set(h,'String',updated_profile_list);
   end
   set(h,'Userdata',updated_full_profile_list);

   return;					% RemoveSessionProfile


% --------------------------------------------------------------------
function SwitchFullPath()
 
   h = findobj(gcf,'Tag','FullPathChkbox');
   use_full_path = get(h,'Value');

   h = findobj(gcf,'Tag','SessionProfileList');	   
   profile_list = get(h,'String');
   full_profile_list = get(h,'Userdata');

   if (use_full_path),
      set(h,'String',full_profile_list);
   else
      num_profiles = length(profile_list);
      for i=1:num_profiles,
         [p_path,p_name,p_ext] = fileparts(profile_list{i});
         profile_list{i} = [p_name p_ext];
      end;
      set(h,'String',profile_list);
   end;

   return;					% SwitchFullPath


% --------------------------------------------------------------------
function MoveUpSessionProfile()

   %  update the session profile list
   %
   h = findobj(gcf,'Tag','SessionProfileList');	   
   list_top = get(h,'ListboxTop');
   profile_idx = get(h,'Value');
   profile_list = get(h,'String');
   full_profile_list = get(h,'Userdata');

   if (profile_idx == 1),		% already on the top of list
      return;
   end;
   
   temp_buffer = profile_list(profile_idx-1);
   profile_list(profile_idx-1) = profile_list(profile_idx);
   profile_list(profile_idx) = temp_buffer;

   temp_buffer = full_profile_list(profile_idx-1);
   full_profile_list(profile_idx-1) = full_profile_list(profile_idx);
   full_profile_list(profile_idx) = temp_buffer;


   curr_value = profile_idx - 1;
   set(h,'String',profile_list,'Userdata',full_profile_list, ...
         'Value',curr_value);

   if (curr_value < list_top)
      set(h,'ListBoxTop',curr_value);
   else
      set(h,'ListBoxTop',list_top);
   end;

   return;					% MoveUpSessionProfile


% --------------------------------------------------------------------
function MoveDownSessionProfile()

   %  update the session profile list
   %
   h = findobj(gcf,'Tag','SessionProfileList');	   
   list_top = get(h,'ListboxTop');
   profile_idx = get(h,'Value');
   profile_list = get(h,'String');
   full_profile_list = get(h,'Userdata');

   if (profile_idx == length(profile_list)),	% already on the top of list
      return;
   end;
   
   temp_buffer = profile_list(profile_idx+1);
   profile_list(profile_idx+1) = profile_list(profile_idx);
   profile_list(profile_idx) = temp_buffer;

   temp_buffer = full_profile_list(profile_idx+1);
   full_profile_list(profile_idx+1) = full_profile_list(profile_idx);
   full_profile_list(profile_idx) = temp_buffer;

   set(h,'String',profile_list,'Userdata',full_profile_list, ...
         'Value',profile_idx+1);
   set(h,'ListBoxTop',list_top);

   return;					% MoveDownSessionProfile


% --------------------------------------------------------------------
function SetEditAlignment()

   h = findobj(gcf,'Tag','FilterEdit');
   set(h,'Units','characters');

   pos = get(h,'Position'); 

   dir_name = get(h,'String');
   len = length(dir_name);

   if (len > pos(3)+5),
      set(h,'HorizontalAlignment','right','String',dir_name);
   else
      set(h,'HorizontalAlignment','left','String',dir_name);
   end;

   set(h,'Units','normal');

   return;					% SetEditAlignment


% --------------------------------------------------------------------
function EditFilter()

   filename = get(gcbo,'String');
   [filter_path,filter_name,filter_ext] = fileparts(filename);
   filter_pattern = [filter_name filter_ext];

   setappdata(gcf,'FilterPattern',filter_pattern);

   if isempty(filter_path),
       filter_path = '/';
   end;

   try
       cd (filter_path);
   catch
       msg = 'ERROR: Invalid directory';
       set(findobj(gcf,'Tag','MessageLine'),'String',msg);
       return;
   end;
   
   update_dirlist(filter_path);

   return;					% EditFilter

   

% --------------------------------------------------------------------
function UpdateDirectoryList()

   listed_dir = get(gcbo,'String');
   selected_dir_idx = get(gcbo,'Value');
   dir_info = get(gcbo,'Userdata');

   dir_entry = find([dir_info.is_dir(selected_dir_idx)] == 1);

   if isempty(dir_entry) 		% only file have been selected
      return;
   end;

   if length(selected_dir_idx) > 1,     % set to the first selected directory
      set(gcbo,'Value',selected_dir_idx(1));
      return;
   end;

   if ~(dir_info.is_dir(selected_dir_idx))
      return; 
   else
      selected_dir = dir_info.names{selected_dir_idx};
   end;
   
   %  update the filter edit box
   %
   try 
      cd (selected_dir);
   catch
       msg = 'ERROR: Cannot access the directory';
       set(findobj(gcf,'Tag','MessageLine'),'String',msg);
       return;
   end;

   old_pointer = get(gcf,'Pointer');
   set(gcf,'Pointer','watch');

   curr = pwd;
   if isempty(curr)
      curr = filesep;
   end

   curr_dir = curr;

   filter_pattern = getappdata(gcf,'FilterPattern');
   h = findobj(gcf,'Tag','FilterEdit');
   set(h,'String',fullfile(curr, filter_pattern));

   SetEditAlignment;
   update_dirlist(curr_dir);

   set(gcf,'Pointer',old_pointer);

   return;					% UpdateDirectoryList


% --------------------------------------------------------------------
function update_dirlist(filter_path);

   filter_pattern = getappdata(gcf,'FilterPattern');

   dir_struct = dir(filter_path);
   if isempty(dir_struct)
       msg = 'ERROR: Directory not found!';
       set(findobj(gcf,'Tag','MessageLine'),'String',msg);
       return;
   end;

   old_pointer = get(gcf,'Pointer');
   set(gcf,'Pointer','watch');
   
   dir_list = dir_struct(find([dir_struct.isdir] == 1));
   [sorted_dir_names,sorted_dir_index] = sortrows({dir_list.name}');

   dir_struct = dir([filter_path filesep filter_pattern]);
   if isempty(dir_struct)
      sorted_file_names = [];
   else
      file_list = dir_struct(find([dir_struct.isdir] == 0));
      [sorted_file_names,sorted_file_index] = sortrows({file_list.name}');
   end;

   h = findobj(gcf,'Tag','File/DirectoryList');

   out_names = [sorted_dir_names; sorted_file_names];
   num_dir = length(sorted_dir_names);
   for i=1:num_dir,
      out_names{i} = sprintf('[%s]',sorted_dir_names{i}); 
   end;

   dir_info.is_dir = zeros(1,length(out_names));
   dir_info.is_dir(1:num_dir) = 1;
   dir_info.names = [sorted_dir_names; sorted_file_names];

   set(h,'String',out_names,'Userdata',dir_info,'Value',2) 
   
   set(gcf,'Pointer',old_pointer);

   return; 					% update_dirlist

% --------------------------------------------------------------------
function init_selection(selected_files);

   if isempty(selected_files{1}),
       return;
   end;

   set(findobj(gcf,'Tag','FullPathChkbox'),'Value',1);
   
   h = findobj(gcf,'Tag','SessionProfileList');	   
   set(h,'String',selected_files);
   set(h,'Userdata',selected_files);

   return; 					% init_selection


%----------------------------------------------------------------------------
function load_txt

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

   [fn, pn] = uigetfile('*.txt','Open Session Profile Group File');
   grp_file = [pn filesep fn];

   try
      full_profile_list = fmri_read_profiles(grp_file);
   catch
      return;
   end

   num_profiles = length(full_profile_list);
   for i=1:num_profiles,
      [junk profile_list{i}] = rri_fileparts(full_profile_list{i});
      full_profile_list{i} = fullfile(pwd, profile_list{i});
   end;

   h = findobj(gcf,'Tag','SessionProfileList');
   set(h,'Userdata',full_profile_list);
   set(h,'String',profile_list);

   if (use_full_path),
      set(h,'String',full_profile_list);
   else
      set(h,'String',profile_list);
   end;

   return


%----------------------------------------------------------------------------
function save_txt

   full_profile_list = get(findobj(gcf,'Tag','SessionProfileList'),'Userdata');

   num_profiles = length(full_profile_list);
   for i=1:num_profiles,
      [junk profile_list{i}] = rri_fileparts(full_profile_list{i});
   end;

   [fn, pn] = uiputfile('*.txt','Save Session Profile Group File');

   if ~fn
      return;
   else
      grp_file = [pn filesep fn];

      try
         fmri_save_profiles(grp_file, profile_list);
      catch
         msg = 'Cannot Save Session Profile Group File';
         uiwait(msgbox(msg,'ERROR'));
      end
   end

   return


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

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

       fmri_select_profiles_pos = get(gcbf,'position');

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

   return;

⌨️ 快捷键说明

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