Copying std::vector contents to TypedArray
Afficher commentaires plus anciens
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;
}
Réponse acceptée
Plus de réponses (1)
Paulo Urriza
le 16 Mai 2023
Modifié(e) : Paulo Urriza
le 16 Mai 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());
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!