Home > vbmeg > functions > common > utility > vb_util_omit_list.m

vb_util_omit_list

PURPOSE ^

omit string or numerical list from baseline list

SYNOPSIS ^

function [new_list,idx] = vb_util_omit_list(base_list, target_list)

DESCRIPTION ^

 omit string or numerical list from baseline list
 [usage]
   [new_list,idx] = vb_util_omit_list(base_list, target_list)
 [input]
     base_list : <required> baseline string list. [Nx1] or [1xN]
   target_list : <required> target string list to be omitted. [Nx1] or [1xN]
 [output]
      new_list : new list that is omitted 'target_list' from 'base_list'
               : [Nx1]
           idx : indices of base_list
 [note]
   @see vb_util_arrange_list
 [history]
   2008-02-27 (Sako) initial version
   2009-08-10 (Sako) modified the case that new_list is empty

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [new_list,idx] = vb_util_omit_list(base_list, target_list)
0002 % omit string or numerical list from baseline list
0003 % [usage]
0004 %   [new_list,idx] = vb_util_omit_list(base_list, target_list)
0005 % [input]
0006 %     base_list : <required> baseline string list. [Nx1] or [1xN]
0007 %   target_list : <required> target string list to be omitted. [Nx1] or [1xN]
0008 % [output]
0009 %      new_list : new list that is omitted 'target_list' from 'base_list'
0010 %               : [Nx1]
0011 %           idx : indices of base_list
0012 % [note]
0013 %   @see vb_util_arrange_list
0014 % [history]
0015 %   2008-02-27 (Sako) initial version
0016 %   2009-08-10 (Sako) modified the case that new_list is empty
0017 %
0018 % Copyright (C) 2011, ATR All Rights Reserved.
0019 % License : New BSD License(see VBMEG_LICENSE.txt)
0020 
0021 % --- CHECK ARGUMENTS --- %
0022 if ~exist('base_list', 'var'), base_list = []; end
0023 if ~exist('target_list', 'var'), target_list = []; end
0024 [base_list, target_list, mode] = ...
0025   inner_check_arguments(base_list, target_list);
0026 
0027 % --- MAIN PROCEDURE --------------------------------------------------------- %
0028 %
0029 idx = [];
0030 list_len = length(base_list);
0031 switch mode
0032   case 0 % string
0033     new_list = cell(1);
0034     new_cnt = 1;
0035     for i_elm = 1:list_len
0036       if ~any(strcmp(base_list{i_elm}, target_list))
0037         idx = [idx;i_elm];
0038         new_list{new_cnt} = base_list{i_elm};
0039         new_cnt = new_cnt + 1;
0040       end
0041     end
0042     
0043   case 1 % numeric
0044     new_list = [];
0045     for i_elm = 1:list_len
0046       if ~any(base_list(i_elm) == target_list)
0047         idx = [idx;i_elm];
0048         new_list = [new_list; base_list(i_elm)];
0049       end
0050     end
0051 end
0052 
0053 if ~isempty(new_list{1})
0054   new_list = vb_util_arrange_list(new_list);
0055   idx = vb_util_arrange_list(idx);
0056 else
0057   new_list = [];
0058   idx = [];
0059 end
0060 return;
0061 %
0062 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0063 
0064 % --- INNER FUNCTIONS -------------------------------------------------------- %
0065 %
0066 % --- inner_check_arguments()
0067 %
0068 function [base_list, target_list, mode] = ...
0069   inner_check_arguments(base_list, target_list)
0070 func_ = mfilename;
0071 if isempty(base_list)
0072   error('(%s)base_list is a required parameter', func_);
0073 end
0074 
0075 if isempty(target_list)
0076   error('(%s)target_list is a required parameter', func_);
0077 end
0078 
0079 if isnumeric(base_list) && isnumeric(target_list)
0080   mode = 1;
0081 elseif ~isnumeric(base_list) && ~isnumeric(target_list)
0082   mode = 0;
0083 else
0084   error('(%s)base_list and target_list are different type', func_);
0085 end
0086 
0087 base_list = vb_util_arrange_list(base_list);
0088 target_list = vb_util_arrange_list(target_list);
0089 return;
0090 %
0091 % --- end of inner_check_arguments()
0092 %
0093 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0094 
0095 %%% END OF FILE %%%

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005