Anthony Blake
Anthony Blake

Reputation: 5348

Reading binary file with Octave

I'm trying to a binary file consisting of floats with Octave (on OS X), but I'm getting the following error:

octave-3.2.3:2> load Input.dat R -binary
error: load: failed to read matrix from file `Input.dat'

The file was written like so:

std::ofstream fout("Input.dat", std::ios::trunc | std::ios::binary);
fout.write(reinterpret_cast<char*>(Buf), N*sizeof(double));
fout.close();

Any idea what could be going wrong here?

Upvotes: 1

Views: 3314

Answers (1)

Justin Peel
Justin Peel

Reputation: 47082

load Input.dat R -binary expects the file Input.dat to be in Octave's binary file format.

You need to figure out what Octave's binary format is if you want to do it like that. However, if instead you want to output the file from C++ as you have, then you can read it in using Octave's fopen and fread functions.

Upvotes: 1

Related Questions