Editing Octave load

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
{{Warning|This article is '''outdated'''.  For current C++ code examples see the Octave Manual https://octave.org/doc/latest/Standalone-Programs.html.}}


The code below shows an example of how to load a matrix from a file in Octave's binary file format.
The code below shows an example of how to load a matrix from a file in Octave's binary file format.
An example of how to load data from a file in Octave's ascii format can be found in this [[fortran|page]].
An example of how to load data from a file in Octave's ascii format can be found in this page [[fortran|page]].


{{Code|octave_binary_io_example.cc: C++ function to load a matrix from a BINARY file in Octave native format|<syntaxhighlight lang="C" style="font-size:13px">
{{Code|octave_binary_io_example.cc: C++ function to load a matrix from a BINARY file in Octave native format|<syntaxhighlight lang="C" style="font-size:13px">
Line 20: Line 19:
std::fstream file;
std::fstream file;
std::ios::openmode m = std::ios::in;
std::ios::openmode m = std::ios::in;
bool check_gzip_magic (const std::string& fname);
bool fexists (const std::string& fname);
load_save_format format = LS_BINARY;
load_save_format format = LS_BINARY;
oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_unknown;
oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_unknown;
Line 26: Line 27:
int main (void)
int main (void)
{
{
  int mode = 1;
  double **data;
  int *rank;
  int **shape;
   string_vector argv (1);
   string_vector argv (1);


Line 53: Line 58:
To test, type the following in Octave:
To test, type the following in Octave:


{{Code||<syntaxhighlight lang="Octave" style="font-size:13px">
{{Code|octave_binary_io_example.cc: C++ function to load a matrix from a BINARY file in Octave native format|<syntaxhighlight lang="Octave" style="font-size:13px">


>> test_var = randn(5);
>> test_var = randn(5);
Line 60: Line 65:


</syntaxhighlight>}}
</syntaxhighlight>}}
Compile and run the example with the following commads
{{Code||<syntaxhighlight lang="bash" style="font-size:13px">
$ mkoctfile --link-stand-alone octave_binary_io_example.cc
$ ./a.out
</syntaxhighlight>}}
[[Category:Outdated pages]]
Please note that all contributions to Octave may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Octave:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Templates used on this page: