[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Octave from C++: Saving objects in binary
From: |
Carlo de Falco |
Subject: |
Re: Octave from C++: Saving objects in binary |
Date: |
Mon, 7 Jun 2010 08:26:14 +0200 |
On 7 Jun 2010, at 07:27, Chidambaram Annamalai wrote:
I need to create large random matrices and perform computations with
them, finally saving the results to a file.
I had no trouble in creating the matrices in C++ after including the
necessary octave headers like so:
octave_rand gauss;
gauss.normal_distribution();
std::cout << "Creating gaussian random matrix... ";
Matrix A = gauss.matrix(M, N);
However, supposing I want to save this matrix A to a file how do I go
about doing that?
I tried the "feval" method provided here:
http://wiki.octave.org/wiki.pl?CategoryExternal but there's a problem.
The "save" function that I'm interested in, will only take string
arguments and when I supply it with the argument "A" to save to a
binary file it shows the error:
warning: save: no such variable `A'
Now how do I tell the "save" function to take the matrix A then? The
problem seems to be that the variable A is not being created in the
memory that is being seen by "save". How do I do that?
Thanks,
Chillu
I'm not sure using feval is the simplest approach,
you could use
#include <octave/load-save.h>
#include <octave/ls-oct-binary.h>
std::ofstream os ("A.mat");
bool boolvar(false);
write_header (os, LS_BINARY);
save_binary_data (os, octave_value (A),
std::string("A"), std::string(""),
boolvar, boolvar);
os.close();
instead.
HTH,
c.