Home > functions > internal > dsRemoveKeyval.m

dsRemoveKeyval

PURPOSE ^

REMOVEKEYVAL - remove keys from keyvals_in.

SYNOPSIS ^

function keyvals_out = dsRemoveKeyval(keyvals,keys)

DESCRIPTION ^

REMOVEKEYVAL - remove keys from keyvals_in.

 Usage:
   keyvals_out = dsRemoveKeyval(keyvals_in,keys)

 Examples:
   keyvals=dsRemoveKeyval({'opt1',1,'opt2',2,'opt3',3},'opt2')
   keyvals=dsRemoveKeyval({'opt1',1,'opt2',2,'opt3',3},{'opt2','opt1'})
 
 Author: Jason Sherfey, PhD <jssherfey@gmail.com>
 Copyright (C) 2016 Jason Sherfey, Boston University, USA

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function keyvals_out = dsRemoveKeyval(keyvals,keys)
0002 %REMOVEKEYVAL - remove keys from keyvals_in.
0003 %
0004 % Usage:
0005 %   keyvals_out = dsRemoveKeyval(keyvals_in,keys)
0006 %
0007 % Examples:
0008 %   keyvals=dsRemoveKeyval({'opt1',1,'opt2',2,'opt3',3},'opt2')
0009 %   keyvals=dsRemoveKeyval({'opt1',1,'opt2',2,'opt3',3},{'opt2','opt1'})
0010 %
0011 % Author: Jason Sherfey, PhD <jssherfey@gmail.com>
0012 % Copyright (C) 2016 Jason Sherfey, Boston University, USA
0013 
0014 keyvals_out=keyvals;
0015 
0016 if isempty(keys) || isempty(keyvals)
0017   return
0018 end
0019 
0020 % make sure keys is a cell array of keys to remove
0021 if ~iscell(keys)
0022   keys={keys};
0023 end
0024 
0025 % find keys in keyvals
0026 idx=0;
0027 for k=1:length(keys)
0028   idx=idx|cellfun(@(x)isequal(x,keys{k}),keyvals);
0029 end
0030 % convert to indices of keys in keyvals
0031 ind=find(idx);
0032 if ~isempty(ind)
0033   % remove keys and associated values
0034   keyvals_out([ind ind+1])=[];
0035 end

Generated on Tue 12-Dec-2017 11:32:10 by m2html © 2005