Open Simulink model using Matlab engine for python

조회 수: 21 (최근 30일)
Hariom Singh
Hariom Singh 2018년 9월 12일
편집: svanimisetti 2020년 3월 18일
Installed matlab engine for python as mentioned
https://www.mathworks.com/help/matlab/matlab_external/connect-python-to-running-matlab-session.html
below command in python terminal gave me error
>>> import matlab.engine
>>> eng = matlab.engine.connect_matlab()
>>> eng.sqrt(4.0)
2.0
>>> eng.open_system('fcc_to_icd1.slx')
Too many output arguments
Traceback (most recent call last): File "<stdin>", line 1, in module File "C:\ProgramData\Anaconda3\lib\site-packages\matlab\engine\matlabengine.py", line 78, in _call_ stderr, feval=True).result() File "C:\ProgramData\Anaconda3\lib\site-packages\matlab\engine\futureresult.py", line 68, in result return self._future.result(timeout) File "C:\ProgramData\Anaconda3\lib\site-packages\matlab\engine\fevalfuture.py", line 82, in result self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err) matlab.engine.MatlabExecutionError: Too many output arguments
is there a way to open simulink models using python matlab engine ?

채택된 답변

Stephan
Stephan 2018년 9월 12일
Hi,
make and save a .m-file in your matlab folder containing the following line:
open_system('name of your file')
then call this script from python with:
import matlab.engine
eng = matlab.engine.connect_matlab()
eng.your_script_name(nargout=0)
This should call the script which then calls simulink to open your model.
Best regards
Stephan
  댓글 수: 1
svanimisetti
svanimisetti 2020년 3월 18일
편집: svanimisetti 2020년 3월 18일
Alternatively, just use the following!
>>> eng.open_system('vdp',nargout=0)
Seems to work for me. Also, if you don't care about opening the model in the Simulink GUI, just load the system and run it. If your model defines tout and yout, these are returned back to Python by evaluating the variables from Matlab workspace. Otherwise, the 'results' variable will have the standard output vector/array.
>>> eng.load_system('vdp')
>>> results = eng.sim('vdp')
>>> %#eng.bdclose('vdp')
>>> eng.close_system('vdp',nargout=0)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by