Can I pass complex numbers from C++ to Matlab using feval or similar?

2 ビュー (過去 30 日間)
Gary Frazier
Gary Frazier 2019 年 8 月 19 日
コメント済み: James Tursa 2019 年 8 月 19 日
MATLAB states in the discussion on calling MATLAB from C++ that passed C++ native arguments must be scalars. Is there a way to pass complex numbers to MATLAB? Specifically, I want to use MATLAB to calculate Bessel functions and the argument to besselj must be complex.
Thanks
GF
  1 件のコメント
James Tursa
James Tursa 2019 年 8 月 19 日
Can you point me to a link for this discussion? I don't use the C++ interface myself, but I would be surprised if you could only pass scalar complex values.

サインインしてコメントする。

採用された回答

dpb
dpb 2019 年 8 月 19 日
編集済み: dpb 2019 年 8 月 19 日
See mxCreateNumericMatrix for C interface. It can create a complex array. I suppose there's also a C++ version but "I know nuthink!" about C++.
Or, you can write a wrapper function that calls besselj as
function res=mybesselj(nu,realpart,imaginarypart))
res=besselj(nu,complex(realpart,imaginarypart));
end
or, if your case is such that it is for a specific nu, then that could be fixed and the wrapper function also pass the constant.
Or, if you're not doing really heavy lifting, I guess you could write specific code as string to pass that would include the essence of the wrapper function call that could be populated with the values dynamically. I've never used that technique as have almost always been going the other way to call the language from ML instead but don't see why can't be done if it's "cheap 'n easy!" for small problems...

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by