[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: num2str() question
From: |
John W. Eaton |
Subject: |
Re: num2str() question |
Date: |
Fri, 26 Sep 2003 07:39:01 -0500 |
On 25-Sep-2003, Steven Levine <address@hidden> wrote:
| In <address@hidden>, on 09/25/03
| at 08:15 PM, "John B. Thoo" <address@hidden> said:
|
| >Why doesn't num2str() return 10000 instead of 1e+04 in the last
| >instance? And how do I make it return 10000?
|
| The Octave online help is your friend:
|
| - Function File: num2str (X)
| Convert a number to a string. These functions are not very
| flexible, but are provided for compatibility with MATLAB. For
| better control over the results, use `sprintf' (*note Formatted
| Output::.).
|
| Since it's a function file, you can look at the code, which in my version
| of Octave says:
|
| retval = sprintf ("%g", x);
|
| so whatever controls the %g formatting controls the num2str formatting.
| There's probably a global variable to control the cutover from fixed point
| to exponential format. I don't recall it offhand, so I'll leave it to you
| to find it in the help.
The current version allows
- Function File: int2str (N)
- Function File: num2str (X, PRECISION)
- Function File: num2str (X, FORMAT)
Convert a number to a string. These functions are not very
flexible, but are provided for compatibility with MATLAB. For
better control over the results, use `sprintf' (*note Formatted
Output::).
so you can write
num2str (x, "%f")
or whatever. The PRECISION argument is the number of digits shown
after the decimal point in the %g format, not the value at which %g
automatically switches from %f to %e style formatting.
jwe
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------