Mercurial > hg > ltpda
comparison m-toolbox/classes/@param/display.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 % DISPLAY display a parameter | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: DISPLAY display a parameter | |
5 % Is called for the parameter object when the semicolon is not used. | |
6 % | |
7 % CALL: param('a', 1) | |
8 % txt = display(param('a', 1)); | |
9 % | |
10 % VERSION: $Id: display.m,v 1.54 2011/02/18 16:48:53 ingo Exp $ | |
11 % | |
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
13 | |
14 function varargout = display(varargin) | |
15 | |
16 objs = [varargin{:}]; | |
17 | |
18 txt = {}; | |
19 | |
20 for ii = 1:numel(objs) | |
21 banner = sprintf('---- param %d ----', ii); | |
22 txt{end+1} = banner; | |
23 | |
24 % get key and value | |
25 name = objs(ii).key; | |
26 v = objs(ii).getVal; | |
27 desc = objs(ii).desc; | |
28 | |
29 %%%%%%%%%%%%%%%%%%%% Add Property 'key' %%%%%%%%%%%%%%%%%%%% | |
30 txt{end+1} = ['key: ' name]; | |
31 | |
32 %%%%%%%%%%%%%%%%%%%% Add Property 'val' %%%%%%%%%%%%%%%%%%%% | |
33 | |
34 if isstruct(v) | |
35 %%%%%%%%%% Special case: structures | |
36 txt{end+1} = 'val: structure'; | |
37 nv = numel(v); | |
38 for ss = 1:nv | |
39 if nv > 1, txt{end+1} = sprintf(' --- struct %02d ---', ss); end | |
40 vs = v(ss); | |
41 fields = fieldnames(vs); | |
42 for kk=1:length(fields) | |
43 field = fields{kk}; | |
44 val = vs.(field); | |
45 txt{end+1} = [' ' field ': ' utils.helper.val2str(val, 60)]; | |
46 end | |
47 end | |
48 else | |
49 %%%%%%%%%% All other cases | |
50 txt{end+1} = sprintf('val: %s', utils.helper.val2str(v, 60)); | |
51 end | |
52 | |
53 %%%%%%%%%%%%%%%%%%%% Add property 'description' %%%%%%%%%%%%%%%%%%%% | |
54 %%% Display the description only if it is not empty | |
55 if ~isempty(desc) | |
56 | |
57 if iscell(desc) | |
58 txt{end+1} = ['desc: ' desc(1,:)]; | |
59 for kk = 2:size(desc,1) | |
60 txt{end+1} = [' ' desc(kk,:)]; | |
61 end | |
62 else | |
63 txt{end+1} = ['desc: ' desc]; | |
64 end | |
65 end | |
66 | |
67 banner_end(1:length(banner)) = '-'; | |
68 txt{end+1} = banner_end; | |
69 | |
70 end | |
71 | |
72 %%% Prepare output | |
73 if nargout == 0 | |
74 for ii=1:length(txt) | |
75 disp(sprintf(txt{ii})); | |
76 end | |
77 elseif nargout == 1 | |
78 varargout{1} = txt; | |
79 end | |
80 | |
81 end | |
82 | |
83 |