Is there a way to set the output format in Octave to a given number of significant digits?
Asked Answered
D

1

6

In Octave, format short g sets the numeric output format in the command window to 5 significant digits, and format long g to 15 digits. Is there a way to set it to a different number of digits different from 5 or 15? I know how to use num2str, mat2str... but I prefer it to be a default output format.

I don't think it is possible, but I am asking just in case (it would be quite useful for my use case).

Dispersant answered 29/6, 2021 at 12:1 Comment(3)
You'd probably need to change the default files for format, if that's possible at all (they could be encrypted). Alternatively, it might be possible to create your own class and overwrite the disp() call (which is also the default formatting IIRC).Valve
By the way, please read the tag descriptions of matlab and octave. This question is not about the similarities or differences, thus please use only one (I presume Octave) tag. Otherwise, solutions need to be constrained to functioning in both languages, something which might be difficult in this specific case.Valve
Thank you. Indeed, @kol's answer works great in Octave but not Matlab, so removing the Matlab keyword is ok.Wiring
P
5

I think you need the output_precision function. For example, if you want to have 7 digits in the command window, type this:

output_precision(7)
Positivism answered 29/6, 2021 at 13:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.