help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Octave from C++: Saving objects in binary


From: Chidambaram Annamalai
Subject: Re: Octave from C++: Saving objects in binary
Date: Mon, 7 Jun 2010 13:16:23 +0530

Thanks a lot! This is what I wanted to achieve.

Could you also tell me how I could modify the save_binary_data
function arguments so that the Matrix A is stored in single precision
in the binary file? I believe real matrices in octave are by default
in double precision. I tried float_value (A) but it didn't work.

Thanks,
Chillu

On 6/7/10, Carlo de Falco <address@hidden> wrote:
>
> 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.
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]