|Subject:||Re: Problem with precision|
|Date:||Thu, 16 Jun 2011 18:55:19 +0200|
Try formatted output:
f = fopen("myfile.txt", "w");
fprintf(f, "%.3f\n", mydata);
The string "%.3f\n" is the formatting string, saying that every number
is to be written als fixed point with 3 decimal, and is to be followed
by a newline.
To write in two columns with a tab as separation or with a fixed column
width use: "%.3f\t%.3f\n" or "%8.3f%12.3f\n".
Beware that to write a file with 2 columns the data matrix needs to have
two rows. So if:
mydata = [x1, y1; x2, y2; ...; xn, yn]
fprintf(f, "%.3f\t%.3f\n", mydata');
Notice the conjugation! This is a quirk that octave has to be compatible
On Thu, 2011-06-16 at 16:34 +0200, Fritz Fischer wrote:
> I have a problem with Octave's precision and hope that you can help
> My function writes data to a file, usually using a normal precision.
> But some
> values are written with a very high precision and in the exponential
> Can someone tell me how to fix this? I tried format short and format
> but the output is the same at both settings.
> Since the files are used as input for another program that does not
> understand the exponential format I need to change this.
> Kind regards,
|[Prev in Thread]||Current Thread||[Next in Thread]|