Move a C++ vector into Matlab with API
이전 댓글 표시
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
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Build MATLAB Interface to C++ Library에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!