Mercurial > hg > ltpda
diff m-toolbox/classes/@param/string.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/@param/string.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,51 @@ +% STRING writes a command string that can be used to recreate the input param object. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DESCRIPTION: STRING writes a command string that can be used to recreate the +% input param object. +% +% CALL: cmd = string(param_obj) +% +% INPUT: param_obj - parameter object +% +% OUTPUT: cmd - command string to create the input object +% +% VERSION: $Id: string.m,v 1.13 2011/02/18 16:48:53 ingo Exp $ +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +function varargout = string(varargin) + + objs = [varargin{:}]; + + cmd = ''; + + for ii = 1:numel(objs) + + key = objs(ii).key; + val = objs(ii).getVal; + + if ischar(val) + val_str = ['''' strrep(val, '''', '''''') '''']; + elseif isnumeric(val) + val_str = mat2str(val); + elseif isa(val, 'ltpda_obj') + val_str = string(val); + elseif iscell(val) + val_str = utils.prog.mcell2str(val); + else + error('### Unknown object [%s]', class(val)); + end + + cmd = [cmd 'param(''' key ''', ' val_str ') ']; + end + + %%% Wrap the command only in bracket if the there are more than one object + if numel(objs) > 1 + cmd = ['[' cmd(1:end-1) ']']; + end + + %%% Prepare output + varargout{1} = cmd; +end +