Mercurial > repos > public > sbplib
comparison struct2string.m @ 40:54d3ab296ba0
Added Dictionary class. Added string conversions for a bunch of types. Deprecated some replaced functions.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 12 Oct 2015 10:38:53 +0200 |
parents | 2b4f1d3e5630 |
children | 92247f4bad2f |
comparison
equal
deleted
inserted
replaced
39:7249f105e67b | 40:54d3ab296ba0 |
---|---|
1 function str = struct2string(s) | 1 function str = struct2string(s) |
2 warning('Deprecated! Use toString() instead!'); | |
2 fn = fieldnames(s); | 3 fn = fieldnames(s); |
3 | 4 |
4 if length(fn) == 0 | 5 if length(fn) == 0 |
5 str = '{}'; | 6 str = '{}'; |
6 return | 7 return |
14 end | 15 end |
15 value = s.(fn{end}); | 16 value = s.(fn{end}); |
16 str = [str sprintf('%s: %s}',fn{end}, valueString(value))]; | 17 str = [str sprintf('%s: %s}',fn{end}, valueString(value))]; |
17 end | 18 end |
18 | 19 |
19 function str = valueString(value) | 20 function str = value2string(value) |
20 if ischar(value) | 21 if isnumeric(value) || ischar(value) |
21 str = ['''' value '''']; | 22 str = mat2str(value); |
23 elseif isstruct(value) | |
24 str = struct2string(value); | |
22 else | 25 else |
23 str = mat2str(value); | 26 str = 'NO_STR_REP'; |
24 end | 27 end |
25 end | 28 end |