diff m-toolbox/classes/+utils/@helper/mat2str.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/+utils/@helper/mat2str.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,48 @@
+% 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.4 2011/04/05 12:51:45 mauro Exp $
+%
+% HISTORY:     26-07-2007 Diepholz
+%                 Creation
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function str = mat2str(number)
+  
+  if isempty(number)
+    str = '[]';
+    return
+  end
+  
+  if isvector(number) && isreal(number)    
+    s = size(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, 20);
+  end
+  
+end
+