Mercurial > hg > ltpda
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % STRING writes a command string that can be used to recreate the input param object. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: STRING writes a command string that can be used to recreate the | |
5 % input param object. | |
6 % | |
7 % CALL: cmd = string(param_obj) | |
8 % | |
9 % INPUT: param_obj - parameter object | |
10 % | |
11 % OUTPUT: cmd - command string to create the input object | |
12 % | |
13 % VERSION: $Id: string.m,v 1.13 2011/02/18 16:48:53 ingo Exp $ | |
14 % | |
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
16 | |
17 function varargout = string(varargin) | |
18 | |
19 objs = [varargin{:}]; | |
20 | |
21 cmd = ''; | |
22 | |
23 for ii = 1:numel(objs) | |
24 | |
25 key = objs(ii).key; | |
26 val = objs(ii).getVal; | |
27 | |
28 if ischar(val) | |
29 val_str = ['''' strrep(val, '''', '''''') '''']; | |
30 elseif isnumeric(val) | |
31 val_str = mat2str(val); | |
32 elseif isa(val, 'ltpda_obj') | |
33 val_str = string(val); | |
34 elseif iscell(val) | |
35 val_str = utils.prog.mcell2str(val); | |
36 else | |
37 error('### Unknown object [%s]', class(val)); | |
38 end | |
39 | |
40 cmd = [cmd 'param(''' key ''', ' val_str ') ']; | |
41 end | |
42 | |
43 %%% Wrap the command only in bracket if the there are more than one object | |
44 if numel(objs) > 1 | |
45 cmd = ['[' cmd(1:end-1) ']']; | |
46 end | |
47 | |
48 %%% Prepare output | |
49 varargout{1} = cmd; | |
50 end | |
51 |