How do I pass complex numbers to MATLAB Engine? (Python)
조회 수: 6 (최근 30일)
이전 댓글 표시
In Python I'm doing
import matlab.engine
eng = matlab.engine.start_matlab()
ret = eng.circuit_values(1, 1, 1, 120, -60-103.92j, -60 + 103.92j)
print(complex(ret))
But I get the error
Error using *
Complex integer arithmetic is not supported.
Is there anyway to work around this?
the .m file looks like this
function [VnN] = circuit_values(zA, zB, zC, VAN, VBN, VCN)
VnN = ((1/zA)*VAN + (1/zB)*VBN + (1/zC)*VCN)/((1/zA)+(1/zB)+(1/zC));
end
Any help is appreciated.
댓글 수: 0
답변 (1개)
arushi
2024년 8월 22일
Hi Marvin C
To pass complex numbers to MATLAB from python, you can utilize the 'matlab.double' function and set the 'is_complex' parameter to 'True'.
This will allow you to create an array of complex numbers in Python and then pass it to MATLAB using the MATLAB engine.
Here's a sample Python script that demonstrates this process:
import matlab.engine
eng = matlab.engine.start_matlab()
a = matlab.double([[1.1+2.4j, 3+4j],[5.3,6.7]], is_complex=True)
ret = eng.example(a)
In the above code snippet, the function ‘example’ resides in the ‘.m’ file and this function takes the ‘a’ as an input, produces the output and returns it back to the python script.
Hope this helps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!