Create 2D TypedArray in C++ Using Matlab Engine API
조회 수: 3 (최근 30일)
이전 댓글 표시
I am attempting to copy C++ vectors of doubles to an instance of Matlab using the Matlab Engine API for C++.
Below are 2 functions intended to copy an existing C++ vector and pass it to Matlab. The first function, Compare1DVec(), works as intended with the input vector being copied to A and A being passed to Matlab. When I attempt to compile the second function, Compare2DVec() I get the following compilation error in Visual Studio 2019:
Error C2027 use of undefined type 'matlab::data::GetArrayType<std::vector<double,std::allocator<_Ty>>>'
with
[
_Ty=double
]
MatlabEngine C:\Program Files\MATLAB\R2018b\extern\include\MatlabDataArray\TypedArray.hpp 56
//C++ working for 1D
void MatCppComparator::Compare1DVec( const std::vector<double>& testVec )
{
size_t len = testVec.size();
auto A = mFactory.createArray( { 1, len }, testVec.cbegin(), testVec.cend() );
//mFactory is an instance of matlab::data::ArrayFactory
mMatlabPtr->setVariable( u"data1D", std::move( A ) );
}
//C++ not compiling for 2D
void MatCppComparator::Compare2DVec( const std::vector< std::vector<double> >& testVec )
{
size_t row = testVec.size();
size_t col = testVec[0].size();
//mFactory is an instance of matlab::data::ArrayFactory
auto A = mFactory.createArray( { row, col }, testVec.cbegin(), testVec.cend() );
mMatlabPtr->setVariable( u"data2D", std::move( A ) );
}
If anyone knows how to fix this and copy a 2D C++ vector to a datatype that can be passed to MATLAB, I would be very appreciative.
-Brian
댓글 수: 0
답변 (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!