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!