Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Public Attributes | Static Public Attributes | Friends
jafar::jmath::MATLAB Class Reference

Class for serializing boost arrays into Matlab format. More...


Detailed Description

Class for serializing boost arrays into Matlab format.

Author:
nmansard, jsola

This class is used to pretty-print boost arrays in Matlab format using the << serializer operator. It can be used in two equivalent ways:

Recognized objects are vectors, vector proxies, indirect arrays, ranges, slices, all sorts of matrices and matrix proxies.

For indirect arrays, ranges and slices, one unit is added to each index to comply with Matlab indexing (which states the first element to be number 1, not 0).

The result can be copied from the console and pasted in Matlab. The matrix M will be initialized in Matlab.

Here is an example. The code:

  jblas::ind_array i(2);      // first define the indices
  i(0) = 2;                   //         {boost}  --> [MATLAB]
  i(1) = 0;                   // this is {2, 0}   --> [3, 1]
  ublas::range r(1, 3);       // this is {1, 2}   --> [2, 3]
  ublas::slice s(0, 2, 3);    // this is {0, 2, 4} -> [1, 3, 5]
  jblas::vec v(8);
  jblas::vec8 vb;             // then define some vectors
  randVector(v);
  randVector(vb);
  jblas::vec_range vr(v, r);
  jblas::vec_slice vs(v, s);
  jblas::vec_indirect vi(v, i);

  cout << "\n% Indirect arrays, ranges and slices \n%====================================" << endl;
  cout << "i   = " << (MATLAB) i << endl;
  cout << "r   = " << (MATLAB) r << endl;
  cout << "s   = " << (MATLAB) s << endl;
  cout << "v   = " << (MATLAB) v << endl;

  cout << "vi  = " << (MATLAB) vi << endl;
  cout << "vr  = " << (MATLAB) vr << endl;
  cout << "vs  = " << (MATLAB) vs << endl;
  cout << "vb  = " << (MATLAB) vb << endl;
  cout << "vbi = " << (MATLAB) ublas::project(vb, i) << endl;
  cout << "vbr = " << (MATLAB) ublas::project(vb, r) << endl;
  cout << "vbs = " << (MATLAB) ublas::project(vb, s) << endl;

  jblas::mat M(5, 5);          // check also on matrices
  randMatrix(M);
  jblas::mat_indirect Mi(M, i, i);
  jblas::mat_range Mr(M, r, r);
  jblas::mat_slice Ms(M, s, s);
  cout << "M   = " << (MATLAB) M << endl;
  cout << "Mi  = " << (MATLAB) Mi << endl;
  cout << "Mr  = " << (MATLAB) Mr << endl;
  cout << "Ms  = " << (MATLAB) Ms << endl;

produces:

 % Indirect arrays, ranges and slices
 %====================================
 i   = [ 3, 1 ];
 r   = [ 2, 3 ];
 s   = [ 1, 3, 5 ];
 v   = [  -0.999984,  -0.736924,  0.511211,  -0.0826997,  0.0655345,  -0.562082,  -0.905911,  0.357729 ]';
 vi  = [  0.511211,  -0.999984 ]';
 vr  = [  -0.736924,  0.511211 ]';
 vs  = [  -0.999984,  0.511211,  0.0655345 ]';
 vb  = [  0.358593,  0.869386,  -0.232996,  0.0388327,  0.661931,  -0.930856,  -0.893077,  0.0594004 ]';
 vbi = [  -0.232996,  0.358593 ]';
 vbr = [  0.869386,  -0.232996 ]';
 vbs = [  0.358593,  -0.232996,  0.661931 ]';
 M   = ...
 [   0.342299,  -0.984604,  -0.233169,  -0.866316,  -0.165028 ;
     0.373545,   0.177953,   0.860873,   0.692334,   0.0538576 ;
    -0.81607,  0.307838,  -0.168001,   0.402381,   0.820642 ;
     0.524396,  -0.475094,  -0.905071,   0.472164,  -0.343532 ;
     0.265277,   0.512821,   0.982075,  -0.269323,  -0.505922 ];
 Mi  = ...
 [  -0.168001,  -0.81607 ;
    -0.233169,   0.342299 ];
 Mr  = ...
 [   0.177953,   0.860873 ;
     0.307838,  -0.168001 ];
 Ms  = ...
 [   0.342299,  -0.233169,  -0.165028 ;
    -0.81607, -0.168001,   0.820642 ;
     0.265277,   0.982075,  -0.505922 ];

which can be copied and directly pasted in Matlab.

Definition at line 124 of file matlab.hpp.

#include <matlab.hpp>

List of all members.

Public Member Functions

template<typename bubTemplateVector >
void initFromBubVector (const bubTemplateVector &v1)
template<typename bubTemplateMatrix >
void initFromBubMatrix (const bubTemplateMatrix &m1)
template<typename bubTemplateIndex >
void initFromBubIndex (const bubTemplateIndex &i1)
template<typename T >
 MATLAB (const ublas::vector< T > &v1)
template<typename T , std::size_t N>
 MATLAB (const ublas::bounded_vector< T, N > &v1)
 MATLAB (const ublas::indirect_array<> &i1)
 MATLAB (const ublas::range &r1)
 MATLAB (const ublas::slice &s1)
template<typename T >
 MATLAB (const ublas::vector_indirect< T > &v1)
template<typename T >
 MATLAB (const ublas::vector_range< T > &v1)
template<typename T >
 MATLAB (const ublas::vector_slice< T > &v1)
template<class M >
 MATLAB (const M &m1)

Public Attributes

std::string str

Static Public Attributes

static bool fullPrec
static const size_t prec

Friends

std::ostream & operator<< (std::ostream &os, const MATLAB &m)

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:40 for Jafar by doxygen 1.7.6.1
LAAS-CNRS