Mercurial > hg > ishara
annotate general/tostring.m @ 19:1eb0ea29ec40
Doesn't belong here.
author | samer |
---|---|
date | Thu, 17 Jan 2013 13:32:19 +0000 |
parents | f0a3d7d7a0e3 |
children | ae596261e75f |
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@4 | 16 if prod(sz)<16, s=mat2str(x); |
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 |