Tomographer  v5.4
Tomographer C++ Framework Documentation
Tomographer::MAT Namespace Reference

Utilities and helpers for reading MATLAB .mat files. More...

Classes

class  DimList
 An array of ints which specifies a list of dimensions. More...
 
class  EigenPosSemidefMatrixWithSqrt
 Read a positive semidefinite matrix along with its matrix square root. More...
 
class  Exception
 Base Exception class for errors within our MAT routines. More...
 
class  File
 A MATLAB file open for reading data. More...
 
class  FileOpenError
 Error while opening a MATLAB file. More...
 
struct  GetStdVector
 Ask for this type in Var::value<typename T>() to get an std::vector of the data. More...
 
class  IndexList
 A list of indices with an API for linear or subindices access. More...
 
class  IndexListIterator
 Utility to iterate over a multidim array by increasing linear index. More...
 
class  InvalidIndexError
 Invalid index or index list provided to a routine. More...
 
struct  MatType
 Map matio's constants to C/C++ types. More...
 
struct  MatType< MAT_T_DOUBLE >
 Specialization of MatType for MAT_T_DOUBLE. More...
 
struct  MatType< MAT_T_INT16 >
 Specialization of MatType for MAT_T_INT16. More...
 
struct  MatType< MAT_T_INT32 >
 Specialization of MatType for MAT_T_INT32. More...
 
struct  MatType< MAT_T_INT64 >
 Specialization of MatType for MAT_T_INT64. More...
 
struct  MatType< MAT_T_INT8 >
 Specialization of MatType for MAT_T_INT8. More...
 
struct  MatType< MAT_T_SINGLE >
 Specialization of MatType for MAT_T_DOUBLE. More...
 
struct  MatType< MAT_T_UINT16 >
 Specialization of MatType for MAT_T_UINT16. More...
 
struct  MatType< MAT_T_UINT32 >
 Specialization of MatType for MAT_T_UINT32. More...
 
struct  MatType< MAT_T_UINT64 >
 Specialization of MatType for MAT_T_UINT64. More...
 
struct  MatType< MAT_T_UINT8 >
 Specialization of MatType for MAT_T_UINT8. More...
 
class  Var
 A MATLAB variable in the MAT file. More...
 
class  VarError
 Exception relating to a MATLAB variable in the data file. More...
 
class  VarMatTypeError
 Unknown type of a variable present in the data file. More...
 
class  VarReadError
 Error while reading a variable from the MATLAB data file. More...
 
struct  VarShape
 Describe shape of variable and whether it is complex. More...
 
class  VarTypeError
 Type mismatch (wrong type requested) in a variable read from the MATLAB data file. More...
 
class  VarValueDecoder
 Specializable template which takes care of decoding values. More...
 
class  VarValueDecoder< Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >
 Decoder for Eigen::Matrix types. More...
 
class  VarValueDecoder< EigenPosSemidefMatrixWithSqrt< EigenType_ > >
 Specialization of VarValueDecoder for extracting a positive semidefinite matrix along with sqrt. More...
 
class  VarValueDecoder< GetStdVector< T, IsRowMajor > >
 Specialization of VarValueDecoder to obtain an std::vector with the matrix data. See GetStdVector. More...
 
class  VarValueDecoder< std::vector< Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols >, Alloc > >
 Decoder for a std::vector of elements of type Eigen::Matrix. More...
 
class  VarValueDecoder< T, _IS_NUMERIC_TYPE >
 Interface to read out a single numeric value. More...
 

Functions

template<typename It , typename ValueType = typename std::iterator_traits<It>::value_type>
ValueType getNumEl (It begin, It end)
 Calculate the product of all dimensions. More...
 
std::ostreamoperator<< (std::ostream &out, const DimList &dlist)
 C++ output stream operators for a DimList.
 
template<bool IsRowMajor>
std::ostreamoperator<< (std::ostream &str, const IndexList< IsRowMajor > &indexlist)
 C++ output stream operator for IndexList.
 
template<bool IsRowMajor, typename IntType >
std::ostreamoperator<< (std::ostream &str, const IndexListIterator< IsRowMajor, IntType > &indexlistit)
 C++ output stream operator for IndexListIterator.
 
template<typename T >
VarValueDecoder< T >::RetType value (const Var &var)
 Access the value of the given variable, as a C++ type. More...
 
template<typename T , ENABLED_IF( tomo_internal::has_params_member< VarValueDecoder< T > >::value) >
VarValueDecoder< T >::RetType value (const Var &var, const typename VarValueDecoder< T >::Params &params)
 Access the value of the given variable, as a C++ type. More...
 
std::ostreamoperator<< (std::ostream &str, const VarShape &varshape)
 C++ output stream operator for VarShape .
 

Detailed Description

Utilities and helpers for reading MATLAB .mat files.

The class File represents an open MATLAB file from which you can extract data. Variables inside the file are represented with Var objects.

The actual data can be extracted to some native C++ representation using Var::value<T>() for some selected C++ types. Example:

Tomographer::MAT::File matfile("myfile.mat");
// find the variable in file named `x'
Tomographer::MAT::Var var_x = matfile.var("x");
// get `x' as C++ double. If `x' in the file is not convertible to double, or if
// it is not a scalar, then a VarTypeError is thrown.
double var_x_value = var.value<double>();
// find variable `m' and get it as an Eigen::MatrixXd. Again, if the type is
// incompatible a VarTypeError is thrown.
Tomographer::MAT::Var var = matfile.var("m");
Eigen::MatrixXd matrix = var.value<Eigen::MatrixXd>();

You can extend this mechanism easily to essentially any C++ type. Just specialize the VarValueDecoder template for your C++ type.

Note
Currently, only numeric types are supported. Neither structures nor cell arrays nor function handles can be read.
Also, currently, you can't write data files, you can only read them.

Function Documentation

§ getNumEl()

template<typename It , typename ValueType = typename std::iterator_traits<It>::value_type>
ValueType Tomographer::MAT::getNumEl ( It  begin,
It  end 
)
inline

Calculate the product of all dimensions.

Given two C++/STL-type iterators begin and end, calculate the product of the sequence of elements. For an empty sequence (begin==end), the result is 1.

Definition at line 283 of file ezmatio.h.

§ value() [1/2]

template<typename T >
VarValueDecoder<T>::RetType Tomographer::MAT::value ( const Var var)
inline

Access the value of the given variable, as a C++ type.

This is an alternative syntax for var.value<T>(). See documentation for Var::value().

Definition at line 878 of file ezmatio.h.

§ value() [2/2]

template<typename T , ENABLED_IF( tomo_internal::has_params_member< VarValueDecoder< T > >::value) >
VarValueDecoder<T>::RetType Tomographer::MAT::value ( const Var var,
const typename VarValueDecoder< T >::Params &  params 
)
inline

Access the value of the given variable, as a C++ type.

This is an alternative syntax for var.value<T>(). See documentation for Var::value().

This overload allows to decode the value of the variable with some parameters specifying what exactly is requested. See documentation for VarValueDecoder.

Definition at line 893 of file ezmatio.h.