Calling user matlab functions from Python

I have 4 user created matlab functions "aaa.m, bbb.m, ccc.m and ddd.m" which are stored in a dictionary(dict) as values against keys.
eng = matlab.engine.start_matlab()
eng.addpath(Path)
for key in dict.keys()
matlabFileName = dict[key]
eng.matlabFileName(nargout=0)
eng.quit()
The above code gives the error "matlab.engine.MatlabExecutionError: Undefined function or variable 'matlabFileName'
How do i call a function from matlab engine when the function name is a VARIABLE.
Please help.

댓글 수: 6

Mohammad Sami
Mohammad Sami 2020년 3월 30일
You can try the eval function instead.
By the way i am using python
Mohammad Sami
Mohammad Sami 2020년 3월 30일
편집: Mohammad Sami 2020년 3월 30일
Yes you can use the eval like
eng.eval(matlabFileName , nargout = 0)
Another option is described at the following link
Apologies for marking it urgent. New to python and matlab and have a delivery by tomorrow.
@Mohammad Sami, eval worked perfectly. Thank you.

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

답변 (0개)

카테고리

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

태그

질문:

2020년 3월 30일

댓글:

2020년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by