octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

num2str works differently in 2.1.42,2.1.43


From: John W. Eaton
Subject: num2str works differently in 2.1.42,2.1.43
Date: Fri, 10 Jan 2003 22:23:04 -0600

On 10-Jan-2003, Andy Adler <address@hidden> wrote:

| I don't know whether this is a bug or intentional.
| 
| num2str now puts leading spaces.
| 
| I have some code that does:
|   eval(['fname=p',num2str(idx),';']);
| This no longer works.
| 
| $ /usr/bin/octave-2.1.36.exe -q
| octave-2.1.36:1> ['fname=p',num2str(1),';']
| ans = fname=p1;
| 
| $ /usr/local/oct2143-test/bin/octave-2.1.43.exe -q
| octave-2.1.43:1> ['fname=p',num2str(1),';']
| ans = fname=p          1;

It was somewhat intentional, since the Matlab docs claim that the
default format for num2str is 11.4g.  But that is apparenly not what
is used for scalar values.  Please try the following patch.

Thanks,

jwe


2003-01-10  John W. Eaton  <address@hidden>

        * general/num2str.m: Don't specify field width for scalars.


Index: general/num2str.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/general/num2str.m,v
retrieving revision 1.15
diff -u -r1.15 num2str.m
--- general/num2str.m   18 Dec 2002 20:37:32 -0000      1.15
+++ general/num2str.m   11 Jan 2003 04:21:38 -0000
@@ -39,7 +39,11 @@
        fmt = sprintf ("%%.%dg", arg);
       endif
     else
-      fmt = "%11.4g";
+      if (isscalar (x))
+       fmt = "%.4g";
+      else
+       fmt = "%11.4g";
+      endif
     endif
     if (iscomplex (x))
       error ("num2str: sorry, can't handle complex numbers yet");



reply via email to

[Prev in Thread] Current Thread [Next in Thread]