From octave-maintainers-request at bevo dot che dot wisc dot edu Fri Jan 10 22:23:30 2003 Subject: num2str works differently in 2.1.42,2.1.43 From: "John W. Eaton" To: Andy Adler Cc: octave-maintainers at bevo dot che dot wisc dot edu Date: Fri, 10 Jan 2003 22:23:04 -0600 On 10-Jan-2003, Andy Adler 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 * 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 at @ -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");