annotate general/tostring.m @ 61:eff6bddf82e3
tip
Finally implemented perceptual brightness thing.
author |
samer |
date |
Sun, 11 Oct 2015 10:20:42 +0100 |
parents |
ae596261e75f |
children |
|
rev |
line source |
samer@4
|
1 function s=tostring(varargin)
|
samer@4
|
2 % tostring - Tries to represent values as a sensible string
|
samer@4
|
3 %
|
samer@4
|
4 % tostring :: A -> string.
|
samer@4
|
5 % tostring :: A, B -> string.
|
samer@4
|
6 % etc.
|
samer@4
|
7 %
|
samer@4
|
8 % Multiple inputs are converted to comma-separated string.
|
samer@8
|
9 s=catsep(',',map(@tostr,varargin));
|
samer@7
|
10 end
|
samer@4
|
11
|
samer@4
|
12 function s=tostr(x)
|
samer@4
|
13 if ischar(x), s=x;
|
samer@4
|
14 elseif isnumeric(x),
|
samer@4
|
15 sz=size(x);
|
samer@42
|
16 if prod(sz)<16, s=mat2str(x,5);
|
samer@4
|
17 else s=sprintf('%s[%s]',class(x),mat2str(sz)); end
|
samer@4
|
18 elseif isa(x,'function_handle'), s=func2str(x);
|
samer@4
|
19 if s(1)~='@', s=['@' s]; end
|
samer@4
|
20 elseif isa(x,'func'), s=tostring(x);
|
samer@4
|
21 else s=['obj:' class(x)];
|
samer@4
|
22 end
|
samer@7
|
23 end
|
samer@4
|
24
|