Home > vbmeg > external > iso2mesh > varargin2struct.m

varargin2struct

PURPOSE ^

SYNOPSIS ^

function opt=varargin2struct(varargin)

DESCRIPTION ^

 opt=varargin2struct('param1',value1,'param2',value2,...)
   or
 opt=varargin2struct(...,optstruct,...)

 convert a series of input parameters into a structure

 authors:Qianqian Fang (q.fang <at> neu.edu)
 date: 2012/12/22

 input:
      'param', value: the input parameters should be pairs of a string and a value
       optstruct: if a parameter is a struct, the fields will be merged to the output struct

 output:
      opt: a struct where opt.param1=value1, opt.param2=value2 ...

 license:
     BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details 

 -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function opt=varargin2struct(varargin)
0002 %
0003 % opt=varargin2struct('param1',value1,'param2',value2,...)
0004 %   or
0005 % opt=varargin2struct(...,optstruct,...)
0006 %
0007 % convert a series of input parameters into a structure
0008 %
0009 % authors:Qianqian Fang (q.fang <at> neu.edu)
0010 % date: 2012/12/22
0011 %
0012 % input:
0013 %      'param', value: the input parameters should be pairs of a string and a value
0014 %       optstruct: if a parameter is a struct, the fields will be merged to the output struct
0015 %
0016 % output:
0017 %      opt: a struct where opt.param1=value1, opt.param2=value2 ...
0018 %
0019 % license:
0020 %     BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
0021 %
0022 % -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
0023 %
0024 
0025 len=length(varargin);
0026 opt=struct;
0027 if(len==0) return; end
0028 i=1;
0029 while(i<=len)
0030     if(isstruct(varargin{i}))
0031         opt=mergestruct(opt,varargin{i});
0032     elseif(ischar(varargin{i}) && i<len)
0033         opt=setfield(opt,lower(varargin{i}),varargin{i+1});
0034         i=i+1;
0035     else
0036         error('input must be in the form of ...,''name'',value,... pairs or structs');
0037     end
0038     i=i+1;
0039 end
0040

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