clibgen can not generate operator() in the C++ matrix class.

2 Ansichten (letzte 30 Tage)
Son Tung Dang
Son Tung Dang am 18 Okt. 2021
Beantwortet: Madheswaran am 20 Feb. 2025
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!

Antworten (1)

Madheswaran
Madheswaran am 20 Feb. 2025
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!

Kategorien

Mehr zu Call C++ from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by