How to interact with matlab function (complex array as argument) from Qt (C++)
이전 댓글 표시
I have a matlab function which takes a multi-dimension complex array as argument, and which return a multi-dimension complex array. I'm like to call that in my Qt application.
I've done some study and I understand I can compile my matlab function and call it from Qt. But how can I pass multi-dimension complex array back and forth? In Qt I can do QList<std::complex<double>> as the data type but is that what I can pass to Matlab function? Thanks.
댓글 수: 10
Walter Roberson
2018년 8월 16일
편집: James Tursa
2018년 8월 16일
The method depends upon which MATLAB release you are using. The handling of complex arrays changed as of R2018a.
Peng Ye
2018년 8월 16일
James Tursa
2018년 8월 16일
편집: James Tursa
2018년 8월 16일
R2017b and earlier: Real & Imag data are stored in separate memory blocks.
R2018a and later: Real & Imag data are stored interleaved in a single memory block.
Since you are using R2015b, your real & imag data are stored in two separate memory blocks. This is a MATLAB thing that typically does not match up with very many (any?) other programming languages which store real & imag data in an interleaved fashion (like R2018a). You will probably need to copy the separate real & imag data to a new memory block in an interleaved fashion in order to match it up with the C++ std::complex<double> type.
Walter Roberson
2018년 8월 16일
편집: Walter Roberson
2018년 8월 16일
https://en.cppreference.com/w/cpp/numeric/complex std::complex<double> uses the interleaved format that is new in R2018a, so the interface would perhaps be less work with newer versions.
James discusses this more at https://www.mathworks.com/matlabcentral/answers/390105-r2018a-complex-interleaved-data-is-the-new-memory-model
Peng Ye
2018년 8월 17일
James Tursa
2018년 8월 17일
편집: James Tursa
2018년 8월 17일
What is your Qt code going to do with this data? If you are using R2015b then MATLAB natively stores the real and imag parts separated (discussed above). As long as your Qt code can deal with that OK then this approach avoids a data copy (preferred). But if your Qt code needs to call some complex functions that expect interleaved data, then you will be forced to do a copy-in-copy-out of your data.
Peng Ye
2018년 8월 17일
Peng Ye
2018년 8월 18일
Walter Roberson
2018년 8월 18일
That looks like it should be fairly efficient.
In MATLAB, the equivalent would be
C = complex(A, B);
Peng Ye
2018년 8월 18일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Deploy to C++ Applications Using mwArray API (C++03)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!