Can I pass complex numbers from C++ to Matlab using feval or similar?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!