Boost logo

Boost Users :

Subject: Re: [Boost-users] load a serialized object into Matlab?
From: Jesse Perla (jesseperla_at_[hidden])
Date: 2010-10-26 11:48:49


James C. Sutherland <James.Sutherland <at> utah.edu> writes:

> On Mon, Oct 25, 2010 at 3:27 PM, Daniel Herring <dherring <at> ll.mit.edu>
>wrote:Isn't matlab capable of reading hdf5 files?  That might be a reasonable
>target for boost::serialization.

This was discussed briefly on the ublas list. Someone also told us that
boost::serialization is really not meant for proprietary file formats.

>endeavor.It is probably a better idea to build a MEX interface where the C++
>classes are loaded natively and exported to Matlab.James

One approach is to wrap the MATIO library (which means the MEX wrappers is not
necessary). I wrote upa mediocre and temporary version for loading/saving.
Right now it only supports double values (and probably only compiles on win32)
but you can see the coding approach and hack up the code at will.

////////////////////////
The code looks like the following:
matlab_iostream arch(boost::filesystem::path("...path..."));
ublas::matrix<double> x_1(2,2);
x_1 <<= 1.1, 2.1,
        3.1, 4.1;
arch << named("x_1_matlab", x_1); //Stores in the name "x_1_matlab" in matalb

ublas::vector<double> x_2;
arch >> named("x_1_matlab", x_2); //Loads from the archive into vector

/////////////////////////////////

Here are a few links for the implementation (which supports ublas vectors,
scalars, ublas matrices, and boost::multi_array):
http://econtoolkit.com/browser/libraries/trunk/etk/etk/serialization/named_varia
ble.hpp
http://econtoolkit.com/browser/libraries/trunk/etk/etk/serialization/matlab/matl
ab_iostream.hpp
http://econtoolkit.com/browser/libraries/trunk/etk/etk/serialization/matlab/matr
ix.hpp
http://econtoolkit.com/browser/libraries/trunk/etk/etk/serialization/matlab/scal
ar.hpp
http://econtoolkit.com/browser/libraries/trunk/etk/etk/serialization/matlab/vect
or.hpp

The test suite is in:
http://econtoolkit.com/browser/libraries/trunk/etk/tests/serialization/matlab/te
st_matlab_archive.cpp
http://econtoolkit.com/browser/libraries/trunk/etk/tests/serialization/matlab/te
st_matlab_matrix.cpp
http://econtoolkit.com/browser/libraries/trunk/etk/tests/serialization/matlab/te
st_matlab_vector.cpp
http://econtoolkit.com/browser/libraries/trunk/etk/tests/serialization/matlab/te
st_matlab_multi_array.cpp
http://econtoolkit.com/browser/libraries/trunk/etk/tests/serialization/matlab/te
st_matlab_scalar.cpp

-Jesse


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net