How do I pass complex numbers to MATLAB Engine? (Python)
17 ビュー (過去 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!