MATLAB C++ Complex Numbers

I have a MATLAB function that calculates wave phases using a -j in a multiplication statement. When I compile this into a C++ shared library I get an error that complex integer arithmetic is not supported. I tried substituting complex(0,-1) for -j, but that results in the same error.
Is there any workaround for this?
EDIT: It's MATLAB 7.11.0(R2010b) I'm running it on Windows XP (32 bit.)
I'm able to compile the matlab code into a C++ shared library. The matlab code doesn't do any I/O operations - that is all handled by the c++ natively and then passed into the matlab functions. The compiled library will throw an exception when it hits the complex arithmetic. Using the mclGetLastErrorMessage function I see that the error is "Error using ==> times Complex integer arithmetic is not supported." and then a pointer to the line of the MATLAB file where I use -j.

댓글 수: 2

Siddharth Shankar
Siddharth Shankar 2011년 1월 26일
Tom, could you provide more details? Which release of MATLAB is this? What platform are you running MATLAB on? At what point do you receive the error (provide details of your workflow)? Does the executable that uses this shared library accept any inputs from the user which it then passes to the shared library?
Tom
Tom 2011년 1월 27일
Siddhartha, Thanks for the response. I've edited the post above.
PS: Sorry about the formatting, it seems to ignore blank lines.

댓글을 달려면 로그인하십시오.

 채택된 답변

Philip Borghesani
Philip Borghesani 2011년 1월 27일

3 개 추천

Is your c++ code passing integer or double complex data as an input to the compiled code?
MATLAB can not do complex math on integer types. Test your code from MATLAB exactly the way it will be used before compiling:
>> a=int32(1+i);
>> a*3
Error using .*
Complex integer arithmetic is not supported.
>> b=1+i;
>> b*int32(5)
Error using .*
Complex integer arithmetic is not supported.

댓글 수: 1

Tom
Tom 2011년 1월 28일
Thanks for the response Philip. Turns out I was passing in an int - changing it to a double fixed it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by