changeset 11778:45e71c7d7bb9 release-3-0-x

strings/mat2str.m: Change is_complex to iscomplex, add tests, add missing ;
author kimhanse@gmail.com
date Wed, 21 May 2008 12:26:57 +0200
parents c5d9aaeb306a
children 65e41465c46b
files scripts/ChangeLog scripts/strings/mat2str.m
diffstat 2 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Mon Jun 02 09:50:09 2008 -0400
+++ b/scripts/ChangeLog	Wed May 21 12:26:57 2008 +0200
@@ -1,3 +1,8 @@
+2008-06-02  Kim Hansen  <kimhanse@gmail.com>
+
+	* strings/mat2str.m: Change is_complex to iscomplex, add tests, add
+	missing ;
+
 2008-06-02  John W. Eaton  <jwe@octave.org>
 
 	* linear-algebra/cond.m, miscellaneous/news.m,
@@ -1295,7 +1300,7 @@
 	* testfun/test.m: In error/warning blocks test for an error before
 	a warning to avoid unexpected failures.
 
-2007-10-15  Kim Hansen  i<kimhanse@gmail.com>
+2007-10-15  Kim Hansen  <kimhanse@gmail.com>
 
 	* testfun/assert.m: Correct documentation of absolution versus 
 	relative error tolerance and add tests.
--- a/scripts/strings/mat2str.m	Mon Jun 02 09:50:09 2008 -0400
+++ b/scripts/strings/mat2str.m	Wed May 21 12:26:57 2008 +0200
@@ -74,9 +74,9 @@
     error ("mat2str: X must be two dimensional");
   endif
 
-  x_is_complex = is_complex (x);
+  x_iscomplex = iscomplex (x);
 
-  if (! x_is_complex)
+  if (! x_iscomplex)
     fmt = sprintf ("%%.%dg", n(1));
   else
     if (length (n) == 1 )
@@ -92,7 +92,7 @@
     s = "[]";
   elseif (nel == 1)
     ## Scalar X, don't print brackets
-    if (! x_is_complex)
+    if (! x_iscomplex)
       s = sprintf (fmt, x);
     else
       s = sprintf (fmt, real (x), imag (x));
@@ -100,11 +100,11 @@
   else
     ## Non-scalar X, print brackets
     fmt = [fmt, ","];
-    if (! x_is_complex)
+    if (! x_iscomplex)
       s = sprintf (fmt, x.');
     else
-      x = x.';
-      s = sprintf (fmt, [real(x(:))'; imag(x(:))']);
+      t = x.';
+      s = sprintf (fmt, [real(t(:))'; imag(t(:))']);
     endif
 
     s = ["[", s];
@@ -115,6 +115,11 @@
   endif
 
   if (strcmp ("class", cls))
-    s = [class(x), "(", s, ")"]
+    s = [class(x), "(", s, ")"];
   endif
 endfunction
+
+%!assert (mat2str ([-1/3 + i/7; 1/3 - i/7], [4 2]), "[-0.3333+0.14i;0.3333-0.14i]")
+%!assert (mat2str ([-1/3 +i/7; 1/3 -i/7], [4 2]), "[-0.3333+0i,0+0.14i;0.3333+0i,-0-0.14i]")
+%!assert (mat2str (int16 ([1 -1]), 'class'), "int16([1,-1])")
+