Octave saving matrix of numbers in scientific format

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Octave saving matrix of numbers in scientific format

pkohvaei
Hey all,

I save my matix of numbers with this command:
save ("-ascii", file_name, matrix_name);
and what relies in the file shows as:
 8.45093460e+001 3.16800000e+001 -1.98000000e+000
 8.45300900e+001 3.16800000e+001 -1.98000000e+000
 ...
how could I make a conversion to float format?


Thank you!



--
View this message in context: http://octave.1599824.n4.nabble.com/Octave-saving-matrix-of-numbers-in-scientific-format-tp4646368.html
Sent from the Octave - General mailing list archive at Nabble.com.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Octave saving matrix of numbers in scientific format

bpabbott
Administrator
On Nov 10, 2012, at 8:54 AM, pkohvaei <[hidden email]> wrote:

> Hey all,
>
> I save my matix of numbers with this command:
> save ("-ascii", file_name, matrix_name);
> and what relies in the file shows as:
> 8.45093460e+001 3.16800000e+001 -1.98000000e+000
> 8.45300900e+001 3.16800000e+001 -1.98000000e+000
> ...
> how could I make a conversion to float format?

I'm not sure I understand what you want.  Dud you try the load() command?

Ben
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Octave saving matrix of numbers in scientific format

Sergei Steshenko





----- Original Message -----

> From: Benjamin Abbott <[hidden email]>
> To: pkohvaei <[hidden email]>
> Cc: "[hidden email]" <[hidden email]>
> Sent: Saturday, November 10, 2012 7:25 PM
> Subject: Re: Octave saving matrix of numbers in scientific format
>
> On Nov 10, 2012, at 8:54 AM, pkohvaei <[hidden email]> wrote:
>
>>  Hey all,
>>
>>  I save my matix of numbers with this command:
>>  save ("-ascii", file_name, matrix_name);
>>  and what relies in the file shows as:
>>  8.45093460e+001 3.16800000e+001 -1.98000000e+000
>>  8.45300900e+001 3.16800000e+001 -1.98000000e+000
>>  ...
>>  how could I make a conversion to float format?
>
> I'm not sure I understand what you want.  Dud you try the load() command?
>
> Ben
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

I think the OP wants something like

123.456789

output. And I think OP wants to use the data outside of Octave, and that other application probably expects the fixed point format.

Anyway, being in the OP's shoes I wouldn't even ask - a couple of nested loops and custom format supplied to 'fprintf' trivially solve the problem.

Regards,
  Sergei.

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Octave saving matrix of numbers in scientific format

pkohvaei
In reply to this post by pkohvaei
Hi again, I did try the save command , and the rest of our friend's explanation is quite correct.As I read before , Octave is specifically designed for matrix operations so I prefer to use this one than going for fprintf (which as I read your post mentioning the loops, must not be a matrix-specific command).
Any idea?
Reply | Threaded
Open this post in threaded view
|

Re: Octave saving matrix of numbers in scientific format

Dmitri A. Sergatskov
On Mon, Nov 12, 2012 at 8:58 AM, pkohvaei <[hidden email]> wrote:
Hi again, I did try the save command , and the rest of our friend's
explanation is quite correct.As I read before , Octave is specifically
designed for matrix operations so I prefer to use this one than going for
fprintf (which as I read your post mentioning the loops, must not be a
matrix-specific command).
Any idea?

In Octave fprintf can take matrix argument.

Dmitri.
--


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Octave saving matrix of numbers in scientific format

pkohvaei
In reply to this post by pkohvaei
So then is this the optimal way for saving that matrix in Octave?

regards,
Reply | Threaded
Open this post in threaded view
|

Re: Octave saving matrix of numbers in scientific format

Dmitri A. Sergatskov
Something along the lines of

a = rand(3,5)
fh = fopen("mymatrix.dat", "w")
fmt = [repmat("%f ", 1,5), "\n"]
fprintf(fh, fmt, a)
fclose(fh)

should work.

Dmitri.
--


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Octave saving matrix of numbers in scientific format

pkohvaei
In reply to this post by pkohvaei
Ok I will try this. Thank you very much!