Hi Walter,
There was no problem. You just did not specify the formatting, so a sane
default was chosen. Rounding small number to 0, as is done when saving
in 3 decimal fixed point notation, is in many cases undesirable.
If you want something different, well, specify the formatting.
Martijn
On Thu, 2011-06-16 at 18:55 +0200, Fritz Fischer wrote:
Hi!
Thanks for you quick responses. Ok, I will rewrite my function.
So far I was using
fprintf(fd,['time', num2str(timeStep),'\n']);
Just to learn something - can someone tell me what exactly
was causing the problem?
Kind regards,
Walter
2011/6/16 Martijn<address@hidden>
Hi Fritz,
Try formatted output:
f = fopen("myfile.txt", "w");
fprintf(f, "%.3f\n", mydata);
fclose(f);
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]
then use
fprintf(f, "%.3f\t%.3f\n", mydata');
Notice the conjugation! This is a quirk that octave has to be
compatible
with Matlab.
good luck,
Martijn
On Thu, 2011-06-16 at 16:34 +0200, Fritz Fischer wrote:
> Hello!
>
> I have a problem with Octave's precision and hope that you
can help
> me.
>
> 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
> format:
>
> 44.875
> 40.262
> 35.327
> 30.005
> 20.981
> 6.9638e-28
> 0
> 0
>
> Can someone tell me how to fix this? I tried format short
and format
> long
> 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,
> Walter
>
>
>
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave