Can I call an entire Python script in MatLab?

1 回表示 (過去 30 日間)
badscience
badscience 2019 年 3 月 11 日
回答済み: Vijaya Lakshmi Chagi 2019 年 3 月 14 日
I have MatLab version R2018b. I have a python script that essentially implements the RSK coorespondance for a given permutation. I have tried to code this in MatLab itself but have not had good luck. I was hoping I could run this script in MatLab itself. I know MatLab supports python functions, but want to know if it is possible to call the entire python script in MatLab? Here is the python code:
from bisect import bisect
def RSK(p):
'''Given a permutation p, spit out a pair of Young tableaux'''
P = []; Q = []
def insert(m, n=0):
'''Insert m into P, then place n in Q at the same place'''
for r in range(len(P)):
if m > P[r][-1]:
P[r].append(m); Q[r].append(n)
return
c = bisect(P[r], m)
P[r][c],m = m,P[r][c]
P.append([m])
Q.append([n])
for i in range(len(p)):
insert(int(p[i]), i+1)
return (P,Q)
print(RSK('43512'))

回答 (1 件)

Vijaya Lakshmi Chagi
Vijaya Lakshmi Chagi 2019 年 3 月 14 日
You can call the Python Script from MATLAB through the "system" command on MATLAB command window. This link gives you an understanding on how to call python script from MATLAB.
The other way you can try is to import phyton libraries in MATLAB and then call python functions/objects from MATLAB : http://www.mathworks.com/help/matlab/call-python-libraries.html

カテゴリ

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