Create 2D TypedArray in C++ Using Matlab Engine API

3 Ansichten (letzte 30 Tage)
Brian Coghlan
Brian Coghlan am 22 Jul. 2020
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

Antworten (0)

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