MATLAB: Copying std::vector contents to TypedArray

matlab data api

Is there a better way to copy the contents of a std::vector to a Matlab Array in C++? The following seems long winded.
V is a std::vector in the code below.
matlab::data::ArrayFactory factory;
matlab::data::TypedArray<double> A = factory.createArray<double>({ 1, V.size() });
int i = 0;
for (auto e : V) {
A[i++] = e;
}

Best Answer

I managed to do this out after hooours of testing.
matlab::data::ArrayFactory f;
matlab::data::TypedArray<double> A = f.createArray<double>({1, V.size()}, V.data(), V.data()+V.size());
Source: the `matlab::data::ArrayFactory` page in the following link C++ class to create arrays - MATLAB.
But I can't find a way for the ItType method of supplying the data to work.