Copying std::vector contents to TypedArray
Show older comments
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;
}
Accepted Answer
More Answers (1)
Paulo Urriza
on 16 May 2023
Edited: Paulo Urriza
on 16 May 2023
Type can be deduced automatically if you used the createArray overload for std::iterator.
matlab::data::ArrayFactory f;
auto A = factory.createArray({1, V.size()}, V.begin(), V.end());
Categories
Find more on Call C++ from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!