diff scripts/general/int2str.m @ 4303:e15a96673976

[project @ 2003-01-23 03:03:08 by jwe]
author jwe
date Thu, 23 Jan 2003 03:03:08 +0000
parents 40153a2affd6
children 98e65d1728a1
line wrap: on
line diff
--- a/scripts/general/int2str.m
+++ b/scripts/general/int2str.m
@@ -35,8 +35,29 @@
 
   if (nargin == 1)
     x = round (x);
-    fw = max (log10 (abs (x(:))) + 3);
-    fmt = sprintf ("%%%dd", fw);
+    t = abs (x(:));
+    t = t(t != 0);
+    if (isempty (t))
+      ## All zeros.
+      fmt = "%3d";
+    else
+      ## Maybe have some zeros.
+      nan_inf = isinf (t) | isnan (t);
+      if (any (nan_inf))
+	min_fw = 5;
+      else
+	min_fw = 3;
+      endif
+      t = t(! nan_inf);
+      if (isempty (t))
+	## Only zeros, Inf, and NaN.
+	fmt = "%5d";
+      else
+	## Could have anything.
+	fw = max (floor (max (log10 (t) + 3)), min_fw);
+	fmt = sprintf ("%%%dd", fw);
+      endif
+    endif
     fmt = strcat (repmat (fmt, 1, columns (x)), "\n");
     tmp = sprintf (fmt, round (x.'));
     tmp(length (tmp)) = "";