Create and store a matlab variable within the python matlab engine

3 ビュー (過去 30 日間)
Jeff
Jeff 2018 年 10 月 3 日
回答済み: Jeff 2019 年 1 月 8 日
I understand the MATLAB Engine API for Python does not support sparse matrices. I would like to create a MATLAB sparse matrix and store it in only MATLAB from within the Python MATLAB engine. This code doesn't work as it passes through Python first and gives an error:
import matlab.engine
eng = matlab.engine.start_matlab()
eng.workspace['A'] = eng.sprand(7000.,7000.,.001)
If I try this code:
eng.eval("A = sprand(7000,7000,.001);")
I get the following error:
Error: The expression to the left of the equals sign is not a valid target for an assignment.
If I open matlab, create the sparse matrix A, and then join the session, I can use A as expected.
eng = matlab.engine.connect_matlab()
eng.workspace['x'] = eng.rand(7000,1);
y = eng.eval("A*x;")
However, I am planning to call a script many times on multiple different machines so this workaround wouldn't work for me. Any ideas of how to do this?

採用された回答

Jeff
Jeff 2019 年 1 月 8 日
I simply need to include the argument "nargout=0" like this:
eng.eval("A = sprand(7000,7000,.001);", nargout=0)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall MATLAB from Python についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by