Tomographer  v1.0a
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  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<int MatTypeId> for MAT_T_DOUBLE. More...
 
struct  MatType< MAT_T_INT16 >
 Specialization of MatType<int MatTypeId> for MAT_T_INT16. More...
 
struct  MatType< MAT_T_INT32 >
 Specialization of MatType<int MatTypeId> for MAT_T_INT32. More...
 
struct  MatType< MAT_T_INT64 >
 Specialization of MatType<int MatTypeId> for MAT_T_INT64. More...
 
struct  MatType< MAT_T_INT8 >
 Specialization of MatType<int MatTypeId> for MAT_T_INT8. More...
 
struct  MatType< MAT_T_SINGLE >
 Specialization of MatType<int MatTypeId> for MAT_T_DOUBLE. More...
 
struct  MatType< MAT_T_UINT16 >
 Specialization of MatType<int MatTypeId> for MAT_T_UINT16. More...
 
struct  MatType< MAT_T_UINT32 >
 Specialization of MatType<int MatTypeId> for MAT_T_UINT32. More...
 
struct  MatType< MAT_T_UINT64 >
 Specialization of MatType<int MatTypeId> for MAT_T_UINT64. More...
 
struct  MatType< MAT_T_UINT8 >
 Specialization of MatType<int MatTypeId> 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...
 
struct  VarValueDecoder
 Specializable template which takes care of decoding values. More...
 
struct  VarValueDecoder< Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >
 Decoder for Eigen::Matrix types. More...
 
struct  VarValueDecoder< GetStdVector< T, IsRowMajor > >
 Specialization of VarValueDecoder<T> to obtain an std::vector<> with the matrix data. See GetStdVector. More...
 
struct  VarValueDecoder< std::vector< Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols >, Alloc > >
 Decoder for a std::vector of elements of type Eigen::Matrix. More...
 
struct  VarValueDecoder< T, typename std::enable_if<(std::numeric_limits< T >::is_specialized||Tools::is_complex< T >::value)>::type >
 Interface to read out a single value. More...
 

Functions

template<typename It , typename ValueType = typename std::iterator_traits<It>::value_type>
ValueType get_numel (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<bool IsRowMajor> .
 
template<bool IsRowMajor, typename IntType >
std::ostreamoperator<< (std::ostream &str, const IndexListIterator< IsRowMajor, IntType > &indexlistit)
 C++ output stream operator for IndexListIterator<bool IsRowMajor, typename IntType> .
 
template<typename T >
VarValueDecoder< T >::RetType value (const Var &var)
 
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)
 
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<T> 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

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

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 292 of file ezmatio.h.