13
$\begingroup$

I notice the values I get from octave are rounded to 5 decimal places. How can I increase that to 6 or 8 for example?

$\endgroup$
  • 4
    $\begingroup$ At the octave command prompt, type format long $\endgroup$ – William DeMeo Mar 14 '12 at 4:15
  • 11
    $\begingroup$ Googling "octave precision digits" yielded this as the 7th hit, and the one in which the brief "blurb" in Google page suggested a match. I know absolutely nothing about octave, so I can't vouch for the answer, but it does lead me to wonder... did you try googling? $\endgroup$ – Arturo Magidin Mar 14 '12 at 4:15
14
$\begingroup$

As noted by William DeMeo in the comments, the command format is what you're looking for. In fact, format is common to both Matlab and Octave.

The command is

format options where options are: short for 3 significant figures, long for 15 significant figures, long e (or E) and short e (or E) for using scientific notation ...

More is in manual here link

$\endgroup$
11
$\begingroup$

The real answer was never posted to this and I ended up here while trying to find it. The output_precision command is what you want. Setting format long provides much more than the requested amount of precision. That may be okay, but if you want a specific precision, use output_precision instead.

>> help output_precision
'output_precision' is a built-in function from the file libinterp/corefcn/pr-output.cc

 -- VAL = output_precision ()
 -- OLD_VAL = output_precision (NEW_VAL)
 -- output_precision (NEW_VAL, "local")
     Query or set the internal variable that specifies the minimum
     number of significant figures to display for numeric output.

     When called from inside a function with the "local" option, the
     variable is changed locally for the function and any subroutines it
     calls.  The original variable value is restored when exiting the
     function.

     See also: format, fixed_point_format, output_max_field_width.

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at http://www.octave.org and via the help@octave.org
mailing list.
>> output_precision
ans =  15
>> output_precision(7)
>> a = [1 4.4 4.4^2 4.4^3 4.4^4 4.4^5;]
a =
      1.000000      4.400000     19.360000     85.184000    374.809600   1649.162240
>> output_precision(4)
>> a = [1 4.4 4.4^2 4.4^3 4.4^4 4.4^5;]
a =                                                                                                                                                     
      1.0000      4.4000     19.3600     85.1840    374.8096   1649.1622
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.