view m-toolbox/classes/+utils/@xml/mat2str.m @ 19:69e3d49b4b0c
database-connection-manager
Update ltpda_uo.fromRepository
author
Daniele Nicolodi <nicolodi@science.unitn.it>
date
Mon, 05 Dec 2011 16:20:06 +0100 (2011-12-05)
parents
f0afece42f48
children
line source
+ − % MAT2STR overloads the mat2str operator to set the precision at a central place.
+ − %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ − %
+ − % DESCRIPTION: MAT2STR overloads the mat2str operator to set the
+ − % precision at a central place.
+ − %
+ − % CALL: str = mat2str(number);
+ − % str = mat2str(matrix);
+ − %
+ − % VERSION: $Id: mat2str.m,v 1.2 2010/04/27 15:41:31 ingo Exp $
+ − %
+ − % HISTORY: 26-07-2007 Diepholz
+ − % Creation
+ − %
+ − %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ −
+ − function str = mat2str(number)
+ −
+ − MAX_PRECISION = 20;
+ −
+ − s = size(number);
+ − if s(1) ~= 1 && s(2) ~= 1
+ − str = mat2str(number, MAX_PRECISION);
+ −
+ − elseif isreal(number)
+ −
+ − % For vectors it is faster to use sprintf directly
+ − if s(1) ~= s(2)
+ − str = '[';
+ − else
+ − str = '';
+ − end
+ − if s(1) > s(2)
+ − str = [str sprintf('%.17g;', number)];
+ − else
+ − str = [str sprintf('%.17g ', number)];
+ − end
+ − if s(1) ~= s(2)
+ − str = [str(1:end-1) ']'];
+ − else
+ − str = str(1:end-1);
+ − end
+ −
+ − else
+ − str = mat2str(number, MAX_PRECISION);
+ − end
+ −
+ − % Make sure that the string have brackets (necessary for eval(str))
+ − if ~isempty(str) && str(1) ~= '['
+ − str = ['[' str ']'];
+ − end
+ −
+ − end
+ −