Calling python script from another python script in MATLAB
조회 수: 4 (최근 30일)
이전 댓글 표시
I am trying to run a script test.py in MATLAB. test.py has another function in it named as mymul(x) (stored in script mymul_test) which takes input x and gives the square output.
test.py has the following functions
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 23 12:29:23 2021
@author: kumarg
"""
from mymul_test import mymul
def myfunct_test(words):
return(words)
mymul(2)
mymul_test.py has following
def mymul(y):
p = y*y
return(p)
When I run
cal = py.mymul_test.mymul(2)
cal =
4
but when i run
>> cal = py.test.mymul(2)
Undefined variable "py" or class "py.test.mymul".
>> cal=py.test.mymul;
Undefined variable "py" or class "py.test.mymul".
Where I am doing wrong?
댓글 수: 0
답변 (1개)
Yongjian Feng
2021년 10월 3일
Try to add the folder of your mymul_text.py to the PYTHONPATH env.
Ref:
댓글 수: 1
Sean de Wolski
2021년 10월 3일
This makes it easier: py_addpath(directory, MATLAB_too) - File Exchange - MATLAB Central (mathworks.com)
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!