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 CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by