MRPT  1.9.9
utils_matlab.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 /** \file Provide helper functions for MEX/MATLAB.
12  * This file can be safely included without checking MRPT_HAS_MATLAB
13  */
14 
15 #include <mrpt/config.h>
16 #if MRPT_HAS_MATLAB
17 #include <mexplus.h>
18 #endif
19 #include <mrpt/math/math_frwds.h>
20 
21 namespace mrpt::math
22 {
23 #if MRPT_HAS_MATLAB
24 /** \addtogroup matlab_grp Helper functions for MEX & MATLAB
25  * \ingroup mrpt_math_grp
26  * @{ */
27 
28 /** Convert vectors, arrays and matrices into Matlab vectors/matrices.
29  * Supported input classes:
30  * - Eigen::Matrix<T,N,1>
31  * - mrpt::math::CVectorFixed<T,N>
32  * - mrpt::math::CMatrixF{*}
33  */
34 template <typename Derived>
36 {
37  const size_t m = mat.rows(), n = mat.cols();
38  mxArray* mxa = mxCreateDoubleMatrix(m, n, mxREAL);
39  double* mxa_data = mxGetPr(
40  mxa); // *IMPORTANT* Matlab stores matrices in *column-major* order!
41  for (size_t j = 0; j < n; j++) // column
42  for (size_t i = 0; i < m; i++) // rows
43  *mxa_data++ = mat.derived().coeff(i, j);
44  return mxa;
45 }
46 
47 /** Convert std::vector<> or std::deque<> of numeric types into Matlab vectors
48  */
49 template <typename CONTAINER>
50 mxArray* convertVectorToMatlab(const CONTAINER& vec)
51 {
52  const size_t m = vec.size(), n = 1;
53  mxArray* mxa = mxCreateDoubleMatrix(m, n, mxREAL);
54  double* mxa_data = mxGetPr(
55  mxa); // *IMPORTANT* Matlab stores matrices in *column-major* order!
56  for (size_t i = 0; i < m; i++) // rows
57  *mxa_data++ = vec[i];
58  return mxa;
59 }
60 
61 /** @} */
62 #endif
63 } // namespace mrpt::math
mxArray * convertToMatlab(const Eigen::EigenBase< Derived > &mat)
Convert vectors, arrays and matrices into Matlab vectors/matrices.
Definition: utils_matlab.h:35
GLenum GLsizei n
Definition: glext.h:5136
This base provides a set of functions for maths stuff.
mxArray * convertVectorToMatlab(const CONTAINER &vec)
Convert std::vector<> or std::deque<> of numeric types into Matlab vectors.
Definition: utils_matlab.h:50
struct mxArray_tag mxArray
Forward declaration for mxArray (avoid #including as much as possible to speed up compiling) ...
Definition: CSerializable.h:18



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019