view general/tostring.m @ 8:f0a3d7d7a0e3

Renamed cat_sep function to catsep
author samer
date Mon, 14 Jan 2013 14:54:10 +0000
parents 47cb292350f3
children ae596261e75f
line wrap: on
line source
function s=tostring(varargin)
% tostring - Tries to represent values as a sensible string
%
% tostring :: A -> string.
% tostring :: A, B -> string.
% etc.
%
% Multiple inputs are converted to comma-separated string.
	s=catsep(',',map(@tostr,varargin));
end
						
function s=tostr(x)
	if ischar(x), s=x;
	elseif isnumeric(x),
		sz=size(x);
		if prod(sz)<16, s=mat2str(x);
		else s=sprintf('%s[%s]',class(x),mat2str(sz)); end
	elseif isa(x,'function_handle'), s=func2str(x);
		if s(1)~='@', s=['@' s]; end
	elseif isa(x,'func'), s=tostring(x);
	else s=['obj:' class(x)];
	end
end