Mercurial > hg > octave-lojdl
changeset 7812:c25094267486
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 | 12c8b195508f |
children | 12a68443191c |
files | scripts/ChangeLog scripts/strings/mat2str.m |
diffstat | 2 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -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-05-20 David Bateman <dbateman@free.fr> * miscellaneous/single.m: Remove.
--- a/scripts/strings/mat2str.m +++ b/scripts/strings/mat2str.m @@ -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])") +