clibgen can not generate operator() in the C++ matrix class.
2 次查看(过去 30 天)
显示 更早的评论
I tried to create a matrix class by C++ which can use some operatr such as * or + to work on matrix or vector.
The header file is listed as,
#pragma once
#include <vector>
#include<iostream>
#define ill_condition pow(10,-14)
class QSMatrix
{
public:
QSMatrix();
QSMatrix(const QSMatrix & rhs);
QSMatrix(unsigned rows_, unsigned cols_);
QSMatrix(unsigned rows_, unsigned cols_, const double & initial_);
~QSMatrix();
void setElement(const unsigned& row, const unsigned& col, double value);
QSMatrix& operator=(const QSMatrix & rhs);
// Matrix mathematical operations
QSMatrix operator+(const QSMatrix & rhs);
QSMatrix & operator+=(const QSMatrix & rhs);
QSMatrix operator-(const QSMatrix & rhs);
QSMatrix & operator-=(const QSMatrix & rhs);
QSMatrix operator*(const QSMatrix & rhs);
QSMatrix & operator*=(const QSMatrix & rhs);
QSMatrix transpose();
// Matrix/scalar operations
QSMatrix operator+(const double& rhs);
QSMatrix operator-(const double& rhs);
QSMatrix operator*(const double& rhs);
QSMatrix operator/(const double& rhs);
double det();
QSMatrix cofactor();
QSMatrix inverse();
// int LUPDecompose(QSMatrix &tempMat, std::vector<double> &p);
// QSMatrix LUPInvert();
// double LUPDeterminant();
// Matrix/vector operations
std::vector<double> operator*(const std::vector<double> & rhs);
std::vector<double> diag_vec();
// Access the individual elements
double & operator()(const unsigned& row, const unsigned& col);
const double & operator()(const unsigned& row, const unsigned& col) const;
// Access the row and column sizes
unsigned get_rows() const;
unsigned get_cols() const;
private:
std::vector<std::vector<double>> val;
unsigned rows;
unsigned cols;
};
After I used the cligen package to generate the MATLAB interface, all methods are generated except ones with operator().
I wonder is that possible to create the operator () interface in MATLAB.
Thank you!
0 个评论
回答(1 个)
Madheswaran
2025-2-20
As of R2024b, MATLAB Interface for C++ doesn't support overloaded operators. You can see the list of limitations to C/C++ Support for MATLAB here: https://www.mathworks.com/help/matlab/matlab_external/limitations-to-cpp-support-in-matlab-cpp-library-interface.html
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call C++ from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!