Home > functions > common > utility > vb_util_check_string_lists.m

vb_util_check_string_lists

PURPOSE ^

check two string lists whether all element of target are included by base

SYNOPSIS ^

function [result,idx] = vb_util_check_string_lists(base, target)

DESCRIPTION ^

 check two string lists whether all element of target are included by base
 [usage]
   [result,idx] = vb_util_check_string_lists(base,target)
 [input]
     base : <required> string list as baseline
          :  - (cell array)
          :  - [n x 1] or [1 x n]
   target : <required> string list that is checked
          :  - (cell array)
          :  - [n x 1] or [1 x n]
 [output]
   result : <<boolean>>
          :   true : base list includes all the elements of target
          :  false : all the elements of target are not included in base
      idx : index of base which are included in target[N x 1]
 [note]
   @see vb_util_arrange_list
 [history]
   2006-12-05 (Sako) initial version
   2007-07-30 (Sako) added return value 'idx'

 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 [result,idx] = vb_util_check_string_lists(base, target)
0002 % check two string lists whether all element of target are included by base
0003 % [usage]
0004 %   [result,idx] = vb_util_check_string_lists(base,target)
0005 % [input]
0006 %     base : <required> string list as baseline
0007 %          :  - (cell array)
0008 %          :  - [n x 1] or [1 x n]
0009 %   target : <required> string list that is checked
0010 %          :  - (cell array)
0011 %          :  - [n x 1] or [1 x n]
0012 % [output]
0013 %   result : <<boolean>>
0014 %          :   true : base list includes all the elements of target
0015 %          :  false : all the elements of target are not included in base
0016 %      idx : index of base which are included in target[N x 1]
0017 % [note]
0018 %   @see vb_util_arrange_list
0019 % [history]
0020 %   2006-12-05 (Sako) initial version
0021 %   2007-07-30 (Sako) added return value 'idx'
0022 %
0023 % Copyright (C) 2011, ATR All Rights Reserved.
0024 % License : New BSD License(see VBMEG_LICENSE.txt)
0025 
0026 % --- CHECK ARGUMENTS --- %
0027 if ~exist('base', 'var'), base = []; end
0028 if ~exist('target', 'var'), target = []; end
0029 [base, target] = inner_check_arguments(base, target);
0030 
0031 % --- MAIN PROCEDURE --------------------------------------------------------- %
0032 %
0033 idx = [];
0034 result = true;
0035 
0036 Ntarget = length(target);
0037 
0038 for i = 1:Ntarget
0039   if sum(strcmp(base, target{i})) == 0
0040     result = false;
0041 %     warning('''%s'' is not included in base', target{i});
0042   else
0043     idx = [idx; find(strcmp(base, target{i}) ~= 0)];
0044   end
0045 end
0046 return;
0047 %
0048 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0049 
0050 % --- INNER FUNCTIONS -------------------------------------------------------- %
0051 %
0052 % --- inner_check_arguments()
0053 %
0054 function [base, target] = inner_check_arguments(base, target)
0055 func_ = mfilename;
0056 if isempty(base)
0057   error('(%s)base is a required parameter', func_);
0058 end
0059 
0060 if isempty(target)
0061   error('(%s)target is a required parameter', func_);
0062 end
0063 
0064 if ~iscell(base)
0065   error('(%s)base must be cell array', func_);
0066 end
0067 
0068 if ~iscell(target)
0069   error('(%s)target must be cell array', func_);
0070 end
0071 
0072 % arrange to [N x 1]
0073 base   = vb_util_arrange_list(base);
0074 target = vb_util_arrange_list(target);
0075 
0076 return;
0077 %
0078 % --- end of inner_check_arguments()
0079 %
0080 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0081 
0082 %%% END OF FILE %%%

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005