Move a C++ vector into Matlab with API
Show older comments
I have a vector of double in C++ that I want to plot in matlab. The length of this vector and the data is decided in the C++ program. How can I pass this variable to Matlab?
I thought i can create a buffer array and copy it to an typed array like:
struct A{
double x,y;
A () : x(distribution_int(generator_int)),y(distribution_int(generator_int)) {};
};
int main(){
int nS = 45;
A a(nS);
matlab::data::TypedArray<double> xData = f.createBuffer<double>(nS); %Why is this illegal??
double* xPtr = xData.get();
for_each(a.begin(), a.end(), [&](const A& e) { *(xPtr++) = e.x; });
return 0;
}
Is there a better way of dealing with this?
Thank!
-Akki
Answers (0)
Categories
Find more on Build MATLAB Interface to C++ Library 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!