Can I call my own custom Matlab functions from python (R2014b)?

조회 수: 10 (최근 30일)
Claire
Claire 2014년 12월 10일
댓글: Tom Sloan 2020년 8월 10일
I've just installed R2014b and am hoping to use the new MATLAB Engine for Python capabilities.
I can successfully call standard functions like isprime from python as shown in the documentation.
Is it possible for me to call my own custom Matlab functions from python using the Engine?

채택된 답변

Bo Li
Bo Li 2014년 12월 10일
Yes, you can also call your own custom MATLAB function from Python Engine. However, you need to add the folder of your own MATLAB file (for example c:\demo\foo.m) into MATLAB path:
>>>eng.addpath(r'c:\demo',nargout=0)
>>>eng.foo()
or change to the directory where your MATLAB file is located:
>>>eng.cd(r'c:\demo')
>>>eng.foo()
If you already have the folder of your MATLAB file in the search path, you can call it directly from Python:
>>>eng.foo()
  댓글 수: 3
Joshua Bone
Joshua Bone 2020년 6월 17일
What is the purpouse of the "nargout" argument here?
Tom Sloan
Tom Sloan 2020년 8월 10일
@Joshua Bone Its so the engine will know how many variables to expect on the return of the function. You'll find several functions require this (such as the save func). I am not sure why all don't require this. Here's a link to the nargout docs

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

추가 답변 (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