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

vb_util_diff_lists

PURPOSE ^

get difference between two lists

SYNOPSIS ^

function [diff] = vb_util_diff_lists(baselist, rmlist, type)

DESCRIPTION ^

 get difference between two lists
 [usage]
   [diff] = vb_util_diff_lists(baselist, rmlist, type)
 [input]
   baselist : <required> base list [N x 1] or [1 x N]
     rmlist : <required> removed list [N x 1] or [1 x N]
       type : <optional> data type numerical or string
            :   [0]) numerical
            :    1 ) string (unimplemented)
 [output]
       diff : difference between baselist and rmlist
            : [N x 1]
 [note]

 [history]
   2007-07-03 (Sako) initial version

 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 [diff] = vb_util_diff_lists(baselist, rmlist, type)
0002 % get difference between two lists
0003 % [usage]
0004 %   [diff] = vb_util_diff_lists(baselist, rmlist, type)
0005 % [input]
0006 %   baselist : <required> base list [N x 1] or [1 x N]
0007 %     rmlist : <required> removed list [N x 1] or [1 x N]
0008 %       type : <optional> data type numerical or string
0009 %            :   [0]) numerical
0010 %            :    1 ) string (unimplemented)
0011 % [output]
0012 %       diff : difference between baselist and rmlist
0013 %            : [N x 1]
0014 % [note]
0015 %
0016 % [history]
0017 %   2007-07-03 (Sako) initial version
0018 %
0019 % Copyright (C) 2011, ATR All Rights Reserved.
0020 % License : New BSD License(see VBMEG_LICENSE.txt)
0021 
0022 % --- CHECK ARGUMENTS --- %
0023 if ~exist('baselist', 'var') baselist = []; end
0024 if ~exist('rmlist', 'var') rmlist = []; end
0025 if ~exist('type', 'var') type = []; end
0026 [baselist, rmlist, type] = inner_check_arguments(baselist, rmlist, type);
0027 
0028 % --- MAIN PROCEDURE --------------------------------------------------------- %
0029 %
0030 % diff = setdiff(baselist, rmlist);
0031 diff = [];
0032 for cur_num = baselist
0033   if isempty(find(cur_num == rmlist(:)))
0034     diff = [diff;cur_num];
0035   end
0036 end
0037 %
0038 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0039 
0040 % --- INNER FUNCTIONS -------------------------------------------------------- %
0041 %
0042 % --- inner_check_arguments()
0043 %
0044 function [baselist, rmlist, type] = ...
0045   inner_check_arguments(baselist, rmlist, type)
0046 
0047 func_ = 'vb_util_diff_lists';
0048 
0049 if isempty(baselist)
0050   error('(%s)baselist is a required parameter', func_);
0051 end
0052 
0053 if isempty(rmlist)
0054   error('(%s)rmlist is a required parameter', func_);
0055 end
0056 
0057 % arrange to [1 x N] vector
0058 baselist = vb_util_arrange_list(baselist,1);
0059 rmlist = vb_util_arrange_list(rmlist);
0060 
0061 if isempty(type)
0062   type = 0; % numerical
0063 end
0064 return;
0065 %
0066 % --- end of inner_check_arguments()
0067 %
0068 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0069 %%% END OF FILE %%%

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