converting vector<vector<double>> to mwArray
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I am trying to pass a 2 dimensional vector (a matrix) in C++ to a C++ share library matlab function compiled by Matlab Compiler.
I am trying to convert this vector, for example myvect, to the mwArray type so that by matlab function can use it. The myvect has the following format in C++,
vector<vector<double>> myvect(2);
myvect[0].push_back(0.1);
myvect[0].push_back(0.2);
myvect[0].push_back(10);
myvect[0].push_back(20);
I am trying:
mwArray mymtrx(2, 2, mxDOUBLE_CLASS);
mymtrx.SetData(&mymtrx[0][0], 4);
But it does not work. The data in mymtrx is not the same as the data in myvect.
How can I convert myvectinto mwArray type?
Thank you
0 Kommentare
Antworten (1)
Kaustubha Govind
am 22 Feb. 2011
Did you have a typo calling SetData?
mwArray mymtrx(2, 2, mxDOUBLE_CLASS);
mymtrx.SetData(&myvect[0][0], 4);
4 Kommentare
Jonathan Ingber Katz
am 15 Nov. 2020
As Kaustubha Govind said, this in the general case will not work for a vector of vectors. I believe the best way to do this is to recast your vector of vectors as a single vector.
Siehe auch
Kategorien
Mehr zu Deploy to C++ Applications Using mwArray API (C++03) finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!